From 5deb64a87fd70e97da27a025ad11fb8ace0e0b57 Mon Sep 17 00:00:00 2001 From: sct Date: Mon, 21 Dec 2020 18:02:23 +0900 Subject: [PATCH] fix(frontend): allow more special characters in search input fixes #430 --- server/api/themoviedb.ts | 12 +++++++++++- src/hooks/useSearchInput.ts | 14 +++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/server/api/themoviedb.ts b/server/api/themoviedb.ts index 6f87823b6..120306b22 100644 --- a/server/api/themoviedb.ts +++ b/server/api/themoviedb.ts @@ -1,4 +1,5 @@ import axios, { AxiosInstance } from 'axios'; +import logger from '../logger'; export const ANIME_KEYWORD_ID = 210024; @@ -374,7 +375,16 @@ class TheMovieDb { return response.data; } catch (e) { - throw new Error(`[TMDB] Failed to search multi: ${e.message}`); + logger.error('Failed to search multi', { + label: 'TMDB', + errorMessage: e.message, + }); + return { + page: 1, + results: [], + total_pages: 1, + total_results: 0, + }; } }; diff --git a/src/hooks/useSearchInput.ts b/src/hooks/useSearchInput.ts index b761928dd..21cfd9831 100644 --- a/src/hooks/useSearchInput.ts +++ b/src/hooks/useSearchInput.ts @@ -7,8 +7,20 @@ import type { Nullable } from '../utils/typeHelpers'; type Url = string | UrlObject; +const extraEncodes: [RegExp, string][] = [ + [/\(/g, '%28'], + [/\)/g, '%29'], + [/!/g, '%21'], +]; + const encodeURIExtraParams = (string: string): string => { - return encodeURIComponent(string).replace(/!/g, '%21'); + let finalString = encodeURIComponent(string); + + extraEncodes.forEach((encode) => { + finalString = finalString.replace(encode[0], encode[1]); + }); + + return finalString; }; interface SearchObject {