From e39b27a2cb7d88525c446a041f9fbf1553202010 Mon Sep 17 00:00:00 2001 From: Jonathan Bowers Date: Tue, 6 Jan 2015 15:32:00 -0800 Subject: [PATCH] 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. --- src/state.js | 14 +++++++------- test/stateSpec.js | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/state.js b/src/state.js index 6e30d63bc..6ebd4680e 100644 --- a/src/state.js +++ b/src/state.js @@ -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])); @@ -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(''); } diff --git a/test/stateSpec.js b/test/stateSpec.js index 7f2a3b0af..77c9373c6 100644 --- a/test/stateSpec.js +++ b/test/stateSpec.js @@ -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);