From 5b7243049793505e44b6608ea09878c37c95b1f5 Mon Sep 17 00:00:00 2001 From: Nate Abele Date: Thu, 17 Apr 2014 08:51:38 -0400 Subject: [PATCH] feat(UrlMatcher): allow shorthand definitions When defining parameter configurations, `{ param: "default" }` is now equivalent to `{ param: { value: "default" }}`. --- src/urlMatcherFactory.js | 3 ++- test/urlMatcherFactorySpec.js | 7 +++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/urlMatcherFactory.js b/src/urlMatcherFactory.js index 0bb9878f5..0a7c6aa3f 100644 --- a/src/urlMatcherFactory.js +++ b/src/urlMatcherFactory.js @@ -95,7 +95,8 @@ function UrlMatcher(pattern, config) { function paramConfig(param) { if (!config.params || !config.params[param]) return {}; - return config.params[param]; + var cfg = config.params[param]; + return isObject(cfg) ? cfg : { value: cfg }; } this.source = pattern; diff --git a/test/urlMatcherFactorySpec.js b/test/urlMatcherFactorySpec.js index 5be15d9b2..85d3209a6 100644 --- a/test/urlMatcherFactorySpec.js +++ b/test/urlMatcherFactorySpec.js @@ -310,6 +310,13 @@ describe("urlMatcherFactory", function () { expect(m.exec('/users/2/bar')).toEqual({ id: 2, test: "bar" }); expect(m.exec('/users/bar/2')).toBeNull(); }); + + it("should allow shorthand definitions", function() { + var m = new UrlMatcher('/foo/:foo', { + params: { foo: "bar" } + }); + expect(m.exec("/foo")).toEqual({ foo: "bar" }); + }); }); });