From c5e3aa7f5a79d59bbe97281924b6aaede549b47b Mon Sep 17 00:00:00 2001 From: Angelina Filippova Date: Wed, 26 Aug 2020 12:57:00 +0300 Subject: [PATCH] Encode emoji packs names to support special chars --- src/api/emojiPacks.js | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/src/api/emojiPacks.js b/src/api/emojiPacks.js index 7a0c39f6..eadabe2b 100644 --- a/src/api/emojiPacks.js +++ b/src/api/emojiPacks.js @@ -14,7 +14,7 @@ export async function addNewEmojiFile(packName, file, shortcode, filename, host, return await request({ baseURL: baseName(host), - url: `/api/pleroma/emoji/packs/files?name=${packName}`, + url: `/api/pleroma/emoji/packs/files?name=${encodeUri(packName)}`, method: 'post', headers: authHeaders(token), data @@ -22,13 +22,13 @@ export async function addNewEmojiFile(packName, file, shortcode, filename, host, } export function addressOfEmojiInPack(host, packName, name) { - return `${baseName(host)}/emoji/${packName}/${name}` + return `${baseName(host)}/emoji/${encodeUri(packName)}/${name}` } export async function createPack(host, token, packName) { return await request({ baseURL: baseName(host), - url: `/api/pleroma/emoji/packs/create?name=${packName}`, + url: `/api/pleroma/emoji/packs/create?name=${encodeUri(packName)}`, method: 'post', headers: authHeaders(token) }) @@ -37,7 +37,7 @@ export async function createPack(host, token, packName) { export async function deleteEmojiFile(packName, shortcode, host, token) { return await request({ baseURL: baseName(host), - url: `/api/pleroma/emoji/packs/files?name=${packName}&shortcode=${shortcode}`, + url: `/api/pleroma/emoji/packs/files?name=${encodeUri(packName)}&shortcode=${shortcode}`, method: 'delete', headers: authHeaders(token) }) @@ -46,7 +46,7 @@ export async function deleteEmojiFile(packName, shortcode, host, token) { export async function deletePack(host, token, packName) { return await request({ baseURL: baseName(host), - url: `/api/pleroma/emoji/packs/delete?name=${packName}`, + url: `/api/pleroma/emoji/packs/delete?name=${encodeUri(packName)}`, method: 'delete', headers: authHeaders(token) }) @@ -68,7 +68,7 @@ export async function downloadFrom(instanceAddress, packName, as, host, token) { export async function fetchPack(packName, page, pageSize, host, token) { return await request({ baseURL: baseName(host), - url: `/api/pleroma/emoji/packs/show?name=${packName}&page=${page}&page_size=${pageSize}`, + url: `/api/pleroma/emoji/packs/show?name=${encodeUri(packName)}&page=${page}&page_size=${pageSize}`, method: 'get', headers: authHeaders(token) }) @@ -113,7 +113,7 @@ export async function reloadEmoji(host, token) { export async function savePackMetadata(host, token, packName, metadata) { return await request({ baseURL: baseName(host), - url: `/api/pleroma/emoji/packs/update?name=${packName}`, + url: `/api/pleroma/emoji/packs/update?name=${encodeUri(packName)}`, method: 'patch', headers: authHeaders(token), data: { metadata }, @@ -124,7 +124,7 @@ export async function savePackMetadata(host, token, packName, metadata) { export async function updateEmojiFile(packName, shortcode, newShortcode, newFilename, force, host, token) { return await request({ baseURL: baseName(host), - url: `/api/pleroma/emoji/packs/files?name=${packName}`, + url: `/api/pleroma/emoji/packs/files?name=${encodeUri(packName)}`, method: 'patch', headers: authHeaders(token), data: { shortcode, new_shortcode: newShortcode, new_filename: newFilename, force } @@ -132,3 +132,5 @@ export async function updateEmojiFile(packName, shortcode, newShortcode, newFile } const authHeaders = (token) => token ? { 'Authorization': `Bearer ${getToken()}` } : {} + +const encodeUri = (name) => encodeURIComponent(name)