]> Untitled Git - lemmy-ui.git/commitdiff
Use urlencode for search queries (fixes #10)
authorFelix Ableitner <me@nutomic.com>
Wed, 7 Oct 2020 10:39:07 +0000 (12:39 +0200)
committerFelix Ableitner <me@nutomic.com>
Wed, 7 Oct 2020 10:39:07 +0000 (12:39 +0200)
src/shared/components/navbar.tsx
src/shared/components/search.tsx

index 877cdd8e58d2dfa4df3d2abab8b4a461b81d50e7..e3c27bd6f827ce351af084eff705d95821f0a29e 100644 (file)
@@ -137,8 +137,9 @@ export class Navbar extends Component<NavbarProps, NavbarState> {
     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`
       );
     }
   }
index 0172489fcad0e49e175ce7677a7469e89736db9a..af6a6b6ed84c0e68c90f8a12509154c06be04457 100644 (file)
@@ -84,7 +84,7 @@ export class Search extends Component<any, SearchState> {
   };
 
   static getSearchQueryFromProps(q: string): string {
-    return q || '';
+    return decodeURIComponent(q) || '';
   }
 
   static getSearchTypeFromProps(type_: string): SearchType {
@@ -504,11 +504,12 @@ export class Search extends Component<any, SearchState> {
 
   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}`
     );
   }