Skip to content

Commit

Permalink
fix in current name param transformation (#466)
Browse files Browse the repository at this point in the history
  • Loading branch information
djfhe authored Oct 1, 2021
1 parent 7eb07db commit 23e5caa
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/js/Router.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ export default class Router extends String {

// Test the passed name against the current route, matching some
// basic wildcards, e.g. passing `events.*` matches `events.show`
const match = new RegExp(`^${name.replace('.', '\\.').replace('*', '.*')}$`).test(current);
const match = new RegExp(`^${name.replace(/\./g, '\\.').replace(/\*/g, '.*')}$`).test(current);

if ([null, undefined].includes(params) || !match) return match;

Expand Down
26 changes: 26 additions & 0 deletions tests/js/route.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ const defaultZiggy = {
uri: '{locale}/posts/{post}',
methods: ['PUT', 'PATCH'],
},
'events.venues-index': {
uri: 'events/{event}/venues-index',
methods: ['GET', 'HEAD'],
bindings: {
event: 'id',
},
},
'events.venues.index': {
uri: 'events/{event}/venues',
methods: ['GET', 'HEAD'],
Expand Down Expand Up @@ -881,6 +888,25 @@ describe('current()', () => {
same(route().current(), 'events.venues.index');
});

test('does not match similiar named routes', () => {
global.window.location.pathname = '/events/1/venues';

same(route().current('events.venues-index'), false);
same(route().current('events.venues.index'), true);

global.window.location.pathname = '/events/1/venues-index';

same(route().current('events.venues-index'), true);
same(route().current('events.venues.index'), false);
});

test('does not match similiar named routes with wildcards', () => {
global.window.location.pathname = '/events/1/venues-index';

same(route().current('events.venues-index'), true);
same(route().current('events.venues.*'), false);
});

test('can get the current route name without window', () => {
global.Ziggy = undefined;
global.window = undefined;
Expand Down

0 comments on commit 23e5caa

Please sign in to comment.