Skip to content

Commit e39b27a

Browse files
committed
fix(state): allow about.*.** glob patterns
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.
1 parent ede5374 commit e39b27a

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/state.js

+7-7
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,13 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
215215
var globSegments = glob.split('.'),
216216
segments = $state.$current.name.split('.');
217217

218+
//match single stars
219+
for (var i = 0, l = globSegments.length; i < l; i++) {
220+
if (globSegments[i] === '*') {
221+
segments[i] = '*';
222+
}
223+
}
224+
218225
//match greedy starts
219226
if (globSegments[0] === '**') {
220227
segments = segments.slice(indexOf(segments, globSegments[1]));
@@ -230,13 +237,6 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
230237
return false;
231238
}
232239

233-
//match single stars
234-
for (var i = 0, l = globSegments.length; i < l; i++) {
235-
if (globSegments[i] === '*') {
236-
segments[i] = '*';
237-
}
238-
}
239-
240240
return segments.join('') === globSegments.join('');
241241
}
242242

test/stateSpec.js

+1
Original file line numberDiff line numberDiff line change
@@ -612,6 +612,7 @@ describe('state', function () {
612612
expect($state.includes('*.*.*')).toBe(true);
613613
expect($state.includes('about.*.*')).toBe(true);
614614
expect($state.includes('about.**')).toBe(true);
615+
expect($state.includes('about.*.**')).toBe(true);
615616
expect($state.includes('*.about.*')).toBe(false);
616617
expect($state.includes('about.*.*', {person: 'bob'})).toBe(true);
617618
expect($state.includes('about.*.*', {person: 'shawn'})).toBe(false);

0 commit comments

Comments
 (0)