Skip to content

Commit 8ddff88

Browse files
committed
Support checking encoded current params
1 parent 3db38aa commit 8ddff88

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

src/js/Router.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,9 @@ export default class Router extends String {
150150
const isSubset = (subset, full) => {
151151
return Object.entries(subset).every(([key, value]) => {
152152
if (Array.isArray(value) && Array.isArray(full[key])) {
153-
return value.every((v) => full[key].includes(v));
153+
return value.every(
154+
(v) => full[key].includes(v) || full[key].includes(decodeURIComponent(v)),
155+
);
154156
}
155157

156158
if (
@@ -162,7 +164,7 @@ export default class Router extends String {
162164
return isSubset(value, full[key]);
163165
}
164166

165-
return full[key] == value;
167+
return full[key] == value || full[key] == decodeURIComponent(value);
166168
});
167169
};
168170

tests/js/route.test.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1504,13 +1504,22 @@ describe('current()', () => {
15041504
});
15051505

15061506
// https://github.com/tighten/ziggy/issues/844
1507-
test('url containing hash', () => {
1507+
test('url containing encoded hash', () => {
15081508
global.window.location.pathname = '/slashes/foo/Arcbees_c%23_doc.md';
15091509

15101510
expect(route().current()).toBe('slashes');
15111511
expect(route().current('slashes', { slug: 'Arcbees_c#_doc.md' })).toBe(true);
15121512
expect(route().current('slashes', { slug: 'Arcbees_c%23_doc.md' })).toBe(true);
15131513
});
1514+
1515+
test('url containing raw hash', () => {
1516+
// This specific case doesn't really matter because it's not valid, # is a URL anchor and can't be in the path like this
1517+
global.window.location.pathname = '/slashes/foo/Arcbees_c#_doc.md';
1518+
1519+
expect(route().current()).toBe('slashes');
1520+
expect(route().current('slashes', { slug: 'Arcbees_c#_doc.md' })).toBe(true);
1521+
expect(route().current('slashes', { slug: 'Arcbees_c%23_doc.md' })).toBe(true);
1522+
});
15141523
});
15151524

15161525
describe('json', () => {

0 commit comments

Comments
 (0)