diff --git a/src/urlMatcherFactory.js b/src/urlMatcherFactory.js index 07c05bff9..8458a3e27 100644 --- a/src/urlMatcherFactory.js +++ b/src/urlMatcherFactory.js @@ -76,13 +76,13 @@ function UrlMatcher(pattern, config, parentMatcher) { // The regular expression is somewhat complicated due to the need to allow curly braces // inside the regular expression. The placeholder regexp breaks down as follows: // ([:*])([\w\[\]]+) - classic placeholder ($1 / $2) (search version has - for snake-case) - // \{([\w\[\]]+)(?:\:( ... ))?\} - curly brace placeholder ($3) with optional regexp/type ... ($4) (search version has - for snake-case + // \{([\w\[\]]+)(?:\:\s*( ... ))?\} - curly brace placeholder ($3) with optional regexp/type ... ($4) (search version has - for snake-case // (?: ... | ... | ... )+ - the regexp consists of any number of atoms, an atom being either // [^{}\\]+ - anything other than curly braces or backslash // \\. - a backslash escape // \{(?:[^{}\\]+|\\.)*\} - a matched set of curly braces containing other atoms - var placeholder = /([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g, - searchPlaceholder = /([:]?)([\w\[\]-]+)|\{([\w\[\]-]+)(?:\:((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g, + var placeholder = /([:*])([\w\[\]]+)|\{([\w\[\]]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g, + searchPlaceholder = /([:]?)([\w\[\]-]+)|\{([\w\[\]-]+)(?:\:\s*((?:[^{}\\]+|\\.|\{(?:[^{}\\]+|\\.)*\})+))?\}/g, compiled = '^', last = 0, m, segments = this.segments = [], parentParams = parentMatcher ? parentMatcher.params : {}, diff --git a/test/urlMatcherFactorySpec.js b/test/urlMatcherFactorySpec.js index 38b694ac4..755c54d2f 100755 --- a/test/urlMatcherFactorySpec.js +++ b/test/urlMatcherFactorySpec.js @@ -520,6 +520,12 @@ describe("urlMatcherFactory", function () { expect(m.format({ foo: 5, flag: true })).toBe("/5/1"); }); + it("should match built-in types with spaces", function () { + var m = new UrlMatcher("/{foo: int}/{flag: bool}"); + expect(m.exec("/1138/1")).toEqual({ foo: 1138, flag: true }); + expect(m.format({ foo: 5, flag: true })).toBe("/5/1"); + }); + it("should match types named only in params", function () { var m = new UrlMatcher("/{foo}/{flag}", { params: {