Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/js/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ export default class Router extends String {
const isSubset = (subset, full) => {
return Object.entries(subset).every(([key, value]) => {
if (Array.isArray(value) && Array.isArray(full[key])) {
return value.every((v) => full[key].includes(v));
return value.every(
(v) => full[key].includes(v) || full[key].includes(decodeURIComponent(v)),
);
}

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

return full[key] == value;
return full[key] == value || full[key] == decodeURIComponent(value);
});
};

Expand Down
19 changes: 19 additions & 0 deletions tests/js/route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1502,6 +1502,25 @@ describe('current()', () => {

global.window = oldWindow;
});

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

expect(route().current()).toBe('slashes');
expect(route().current('slashes', { slug: 'Arcbees_c#_doc.md' })).toBe(true);
expect(route().current('slashes', { slug: 'Arcbees_c%23_doc.md' })).toBe(true);
});

test('url containing raw hash', () => {
// This specific case may not matter because it's not valid, # is a URL anchor and
// can't be in the path like this, but in general this should work both ways
global.window.location.pathname = '/slashes/foo/Arcbees_c#_doc.md';

expect(route().current()).toBe('slashes');
expect(route().current('slashes', { slug: 'Arcbees_c#_doc.md' })).toBe(true);
expect(route().current('slashes', { slug: 'Arcbees_c%23_doc.md' })).toBe(true);
});
});

describe('json', () => {
Expand Down
Loading