From cf7850f0d204347f761c63e0c686f1ab520757d7 Mon Sep 17 00:00:00 2001 From: fef Date: Sun, 11 Dec 2022 13:26:23 +0000 Subject: [PATCH] fix 404 when reacting with Keycap Number Sign The Unicode sequence for this emoji starts with an ASCII # character, which the browser's URI parser truncates before sending the request to the backend. --- app/javascript/flavours/glitch/actions/interactions.js | 6 ++++-- app/javascript/mastodon/actions/interactions.js | 6 ++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/app/javascript/flavours/glitch/actions/interactions.js b/app/javascript/flavours/glitch/actions/interactions.js index da06afadf1..8f515c990c 100644 --- a/app/javascript/flavours/glitch/actions/interactions.js +++ b/app/javascript/flavours/glitch/actions/interactions.js @@ -416,7 +416,9 @@ export const addReaction = (statusId, name, url) => (dispatch, getState) => { dispatch(addReactionRequest(statusId, name, url)); } - api(getState).post(`/api/v1/statuses/${statusId}/react/${name}`).then(() => { + // encodeURIComponent is required for the Keycap Number Sign emoji, see: + // + api(getState).post(`/api/v1/statuses/${statusId}/react/${encodeURIComponent(name)}`).then(() => { dispatch(addReactionSuccess(statusId, name)); }).catch(err => { if (!alreadyAdded) { @@ -448,7 +450,7 @@ export const addReactionFail = (statusId, name, error) => ({ export const removeReaction = (statusId, name) => (dispatch, getState) => { dispatch(removeReactionRequest(statusId, name)); - api(getState).post(`/api/v1/statuses/${statusId}/unreact/${name}`).then(() => { + api(getState).post(`/api/v1/statuses/${statusId}/unreact/${encodeURIComponent(name)}`).then(() => { dispatch(removeReactionSuccess(statusId, name)); }).catch(err => { dispatch(removeReactionFail(statusId, name, err)); diff --git a/app/javascript/mastodon/actions/interactions.js b/app/javascript/mastodon/actions/interactions.js index 4f80b933d6..28c728d61e 100644 --- a/app/javascript/mastodon/actions/interactions.js +++ b/app/javascript/mastodon/actions/interactions.js @@ -436,7 +436,9 @@ export const addReaction = (statusId, name, url) => (dispatch, getState) => { dispatch(addReactionRequest(statusId, name, url)); } - api(getState).post(`/api/v1/statuses/${statusId}/react/${name}`).then(() => { + // encodeURIComponent is required for the Keycap Number Sign emoji, see: + // + api(getState).post(`/api/v1/statuses/${statusId}/react/${encodeURIComponent(name)}`).then(() => { dispatch(addReactionSuccess(statusId, name)); }).catch(err => { if (!alreadyAdded) { @@ -468,7 +470,7 @@ export const addReactionFail = (statusId, name, error) => ({ export const removeReaction = (statusId, name) => (dispatch, getState) => { dispatch(removeReactionRequest(statusId, name)); - api(getState).post(`/api/v1/statuses/${statusId}/unreact/${name}`).then(() => { + api(getState).post(`/api/v1/statuses/${statusId}/unreact/${encodeURIComponent(name)}`).then(() => { dispatch(removeReactionSuccess(statusId, name)); }).catch(err => { dispatch(removeReactionFail(statusId, name, err));