From b5130bb1215e15f832ea6daa670410b9a950c0d4 Mon Sep 17 00:00:00 2001
From: Eddie Monge <eddie@eddiemonge.com>
Date: Thu, 25 Jun 2015 19:25:09 -0700
Subject: [PATCH] fix(urlMatcherFactory): include the slash in squashed params

Squashed params were ignoring a missing slash before the param so things
like /users123 would match /url/:id

Fixes #2064
---
 src/urlMatcherFactory.js      | 5 ++++-
 test/urlMatcherFactorySpec.js | 1 +
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/urlMatcherFactory.js b/src/urlMatcherFactory.js
index bf116f027..8e8e8d23d 100644
--- a/src/urlMatcherFactory.js
+++ b/src/urlMatcherFactory.js
@@ -103,7 +103,10 @@ function UrlMatcher(pattern, config, parentMatcher) {
     if (!pattern) return result;
     switch(squash) {
       case false: surroundPattern = ['(', ')' + (optional ? "?" : "")]; break;
-      case true:  surroundPattern = ['?(', ')?']; break;
+      case true:
+        result = result.replace(/\/$/, '');
+        surroundPattern = ['(?:\/(', ')|\/)?'];
+      break;
       default:    surroundPattern = ['(' + squash + "|", ')?']; break;
     }
     return result + surroundPattern[0] + pattern + surroundPattern[1];
diff --git a/test/urlMatcherFactorySpec.js b/test/urlMatcherFactorySpec.js
index 8b0c1b678..d4e3d64d8 100755
--- a/test/urlMatcherFactorySpec.js
+++ b/test/urlMatcherFactorySpec.js
@@ -588,6 +588,7 @@ describe("urlMatcherFactory", function () {
         params: { id: { value: null, squash: true } }
       });
       expect(m.exec('/users/1138')).toEqual({ id: 1138 });
+      expect(m.exec('/users1138')).toBeNull();
       expect(m.exec('/users/').id).toBeNull();
       expect(m.exec('/users').id).toBeNull();
     });