fix: Error with search term including %, closes #1891
This commit is contained in:
@@ -74,7 +74,7 @@ export function searchUrl(
|
||||
let route = "/search";
|
||||
|
||||
if (query) {
|
||||
route += `/${encodeURIComponent(query)}`;
|
||||
route += `/${encodeURIComponent(query.replace("%", "%25"))}`;
|
||||
}
|
||||
|
||||
search = search ? `?${search}` : "";
|
||||
|
||||
@@ -28,3 +28,9 @@ export function cdnPath(path: string): string {
|
||||
export function imagePath(path: string): string {
|
||||
return cdnPath(`/images/${path}`);
|
||||
}
|
||||
|
||||
export function decodeURIComponentSafe(text: string) {
|
||||
return text
|
||||
? decodeURIComponent(text.replace(/%(?![0-9][0-9a-fA-F]+)/g, "%25"))
|
||||
: text;
|
||||
}
|
||||
|
||||
14
app/utils/urls.test.js
Normal file
14
app/utils/urls.test.js
Normal file
@@ -0,0 +1,14 @@
|
||||
// @flow
|
||||
import { decodeURIComponentSafe } from "./urls";
|
||||
|
||||
describe("decodeURIComponentSafe", () => {
|
||||
test("to handle % symbols", () => {
|
||||
expect(decodeURIComponentSafe("%")).toBe("%");
|
||||
expect(decodeURIComponentSafe("%25")).toBe("%");
|
||||
});
|
||||
|
||||
test("to correctly account for encoded symbols", () => {
|
||||
expect(decodeURIComponentSafe("%7D")).toBe("}");
|
||||
expect(decodeURIComponentSafe("%2F")).toBe("/");
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user