Skip to content

Commit

Permalink
Merge pull request #668 from tighten/jbk/route-current-cyrillic-fix
Browse files Browse the repository at this point in the history
Fix `route().current()` with encoded characters
  • Loading branch information
bakerkretzmar authored Oct 12, 2023
2 parents de2df7b + cbc85a8 commit 9b11334
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/js/Route.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export default class Route {

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

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

if (matches) {
for (const k in matches.groups) {
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 @@ -184,6 +184,10 @@ const defaultZiggy = {
extension: '\\.(php|html)',
},
},
statistics: {
uri: 'статистика',
methods: ['GET', 'HEAD'],
},
pages: {
uri: '{page}',
methods: ['GET', 'HEAD'],
Expand Down Expand Up @@ -1229,6 +1233,21 @@ describe('current()', () => {
expect(route().current('events.venues.show', { id: 12, user: 'Matt' })).toBe(false);
});

test('can check the current route with Cyrillic characters', () => {
global.window.location.pathname = '/статистика';

expect(route().current()).toBe('statistics');
expect(route().current('statistics')).toBe(true);
});

test('can check the current route with encoded Cyrillic characters', () => {
global.window.location.pathname =
'/%D1%81%D1%82%D0%B0%D1%82%D0%B8%D1%81%D1%82%D0%B8%D0%BA%D0%B0';

expect(route().current()).toBe('statistics');
expect(route().current('statistics')).toBe(true);
});

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

Expand Down

0 comments on commit 9b11334

Please sign in to comment.