Skip to content

Commit

Permalink
fix(state): allow about.*.** glob patterns
Browse files Browse the repository at this point in the history
Previously, it was not possible to match all descendant states without
matching the parent state.

e.g. about.*.** would not match state about.person.item

Move the single * matching logic above the ** so the greedy ** check won't
mismatch.
  • Loading branch information
jonotron committed Jan 8, 2015
1 parent ede5374 commit e39b27a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/state.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,13 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
var globSegments = glob.split('.'),
segments = $state.$current.name.split('.');

//match single stars
for (var i = 0, l = globSegments.length; i < l; i++) {
if (globSegments[i] === '*') {
segments[i] = '*';
}
}

//match greedy starts
if (globSegments[0] === '**') {
segments = segments.slice(indexOf(segments, globSegments[1]));
Expand All @@ -230,13 +237,6 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
return false;
}

//match single stars
for (var i = 0, l = globSegments.length; i < l; i++) {
if (globSegments[i] === '*') {
segments[i] = '*';
}
}

return segments.join('') === globSegments.join('');
}

Expand Down
1 change: 1 addition & 0 deletions test/stateSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -612,6 +612,7 @@ describe('state', function () {
expect($state.includes('*.*.*')).toBe(true);
expect($state.includes('about.*.*')).toBe(true);
expect($state.includes('about.**')).toBe(true);
expect($state.includes('about.*.**')).toBe(true);
expect($state.includes('*.about.*')).toBe(false);
expect($state.includes('about.*.*', {person: 'bob'})).toBe(true);
expect($state.includes('about.*.*', {person: 'shawn'})).toBe(false);
Expand Down

0 comments on commit e39b27a

Please sign in to comment.