From: Felix Ableitner Date: Wed, 7 Oct 2020 10:39:07 +0000 (+0200) Subject: Use urlencode for search queries (fixes #10) X-Git-Url: http://these/git/%7B%60/feeds/front/static/%7BpictrsAvatarThumbnail%28this.state.siteRes.site.icon%29%7D?a=commitdiff_plain;h=3cd200469ffceeb4e2b00730aa6b57bed9b9c191;p=lemmy-ui.git Use urlencode for search queries (fixes #10) --- diff --git a/src/shared/components/navbar.tsx b/src/shared/components/navbar.tsx index 877cdd8..e3c27bd 100644 --- a/src/shared/components/navbar.tsx +++ b/src/shared/components/navbar.tsx @@ -137,8 +137,9 @@ export class Navbar extends Component { if (searchParam === '') { this.context.router.history.push(`/search/`); } else { + const searchParamEncoded = encodeURIComponent(searchParam); this.context.router.history.push( - `/search/q/${searchParam}/type/All/sort/TopAll/page/1` + `/search/q/${searchParamEncoded}/type/All/sort/TopAll/page/1` ); } } diff --git a/src/shared/components/search.tsx b/src/shared/components/search.tsx index 0172489..af6a6b6 100644 --- a/src/shared/components/search.tsx +++ b/src/shared/components/search.tsx @@ -84,7 +84,7 @@ export class Search extends Component { }; static getSearchQueryFromProps(q: string): string { - return q || ''; + return decodeURIComponent(q) || ''; } static getSearchTypeFromProps(type_: string): SearchType { @@ -504,11 +504,12 @@ export class Search extends Component { updateUrl(paramUpdates: UrlParams) { const qStr = paramUpdates.q || this.state.q; + const qStrEncoded = encodeURIComponent(qStr); const typeStr = paramUpdates.type_ || this.state.type_; const sortStr = paramUpdates.sort || this.state.sort; const page = paramUpdates.page || this.state.page; this.props.history.push( - `/search/q/${qStr}/type/${typeStr}/sort/${sortStr}/page/${page}` + `/search/q/${qStrEncoded}/type/${typeStr}/sort/${sortStr}/page/${page}` ); }