Skip to content

Commit 6b39f5d

Browse files
committed
Workaround for regexp.exec() returning '' for unmatched captures on IE (see #24)
1 parent 70b8709 commit 6b39f5d

File tree

4 files changed

+20
-11
lines changed

4 files changed

+20
-11
lines changed

build/angular-ui-states.js

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* State-based routing for AngularJS
3-
* @version v0.0.1 - 2013-02-15
3+
* @version v0.0.1 - 2013-02-17
44
* @link
55
* @license MIT License, http://www.opensource.org/licenses/MIT
66
*/
@@ -147,6 +147,8 @@ function $StateProvider( $urlRouterProvider, $urlMatcherFactory) {
147147
// Derive parent state from a hierarchical name only if 'parent' is not explicitly defined.
148148
var parent = root;
149149
if (!isDefined(state.parent)) {
150+
// regex matches any valid composite state name
151+
// would match "contact.list" but not "contacts"
150152
var compositeName = /^(.+)\.[^.]+$/.exec(name);
151153
if (compositeName != null) {
152154
parent = findState(compositeName[1]);
@@ -572,11 +574,11 @@ function UrlMatcher(pattern) {
572574
// inside the regular expression. The placeholder regexp breaks down as follows:
573575
// :(\w+) colon placeholder ($1)
574576
// \{(\w+)(?:\:( ... ))?\} curly brace placeholder ($2) with optional regexp ... ($3)
575-
// (?: ... | ... | ... )* the regexp consists of any number of atoms, an atom being either
577+
// (?: ... | ... | ... )+ the regexp consists of any number of atoms, an atom being either
576578
// [^{}\\]+ - anything other than curly braces or backslash
577579
// \\. - a backslash escape
578580
// \{(?:[^{}\\]+|\\.)*\} - a matched set of curly braces containing other atoms
579-
var placeholder = /:(\w+)|\{(\w+)(?:\:((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})*))?\}/g,
581+
var placeholder = /:(\w+)|\{(\w+)(?:\:((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g,
580582
names = {}, compiled = '^', last = 0, m,
581583
segments = this.segments = [],
582584
params = this.params = [];
@@ -598,8 +600,8 @@ function UrlMatcher(pattern) {
598600
// The number of segments is always 1 more than the number of parameters.
599601
var id, regexp, segment;
600602
while ((m = placeholder.exec(pattern))) {
601-
id = (m[1] != null) ? m[1] : m[2];
602-
regexp = (m[3] != null) ? m[3] : '[^/]*';
603+
id = m[1] || m[2];
604+
regexp = m[3] || '[^/]*';
603605
segment = pattern.substring(last, m.index);
604606
if (segment.indexOf('?') >= 0) break; // we're into the search part
605607
compiled += quoteRegExp(segment) + '(' + regexp + ')';

0 commit comments

Comments
 (0)