From 6cad7718ebd3bfded3500f09659308ab048b9c0f 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 2d483de818..a7eb7a78dd 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 54592ec535..7433870250 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));