Skip to content

Commit

Permalink
Only decode URI for matching when necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
bakerkretzmar committed Oct 17, 2024
1 parent a8a5984 commit 74ce691
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/js/Route.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ export default class Route {

const [location, query] = url.replace(/^\w+:\/\//, '').split('?');

const matches = new RegExp(`^${pattern}/?$`).exec(decodeURI(location));
const matches =
new RegExp(`^${pattern}/?$`).exec(location) ??
new RegExp(`^${pattern}/?$`).exec(decodeURI(location));

if (matches) {
for (const k in matches.groups) {
Expand Down
7 changes: 7 additions & 0 deletions tests/js/route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1412,6 +1412,13 @@ describe('current()', () => {
expect(route().current('statistics')).toBe(true);
});

test('can check the current route with encoded percent sign', () => {
global.window.location.pathname = '/optionalpage/john%25';

expect(route().current()).toBe('pages.optional');
expect(route().current('pages.optional')).toBe(true);
});

test('can ignore routes that don’t allow GET requests', () => {
global.window.location.pathname = '/posts/1';

Expand Down

0 comments on commit 74ce691

Please sign in to comment.