Skip to content

Commit

Permalink
Merge pull request angular-ui#1680 from jonotron/any-substate-glob
Browse files Browse the repository at this point in the history
fix($state): allow about.*.** glob patterns
  • Loading branch information
nateabele committed Jan 9, 2015
2 parents ede5374 + e39b27a commit 8c97736
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 8c97736

Please sign in to comment.