Permalink
Browse files

Fix URL matching with query params

  • Loading branch information...
1 parent 03620e6 commit c9fd2a93efe03225b8f934c9bcec224b134b2c07 @mdp mdp committed Jun 20, 2012
Showing with 10 additions and 1 deletion.
  1. +1 −1 src/chaplin/lib/route.coffee
  2. +9 −0 test/spec/router_spec.coffee
@@ -56,7 +56,7 @@ define [
# Save parameter name
@paramNames.push paramName
# Replace with a character class
- '([^\/]+)'
+ '([^\/\?]+)'
# Test if the route matches to a path (called by Backbone.History#loadUrl)
test: (path) ->
@@ -89,6 +89,15 @@ define [
expect(params.three).toBe 'ü~ö~ä'
expect(params.four).toBe encodeURIComponent('éêè')
+ it 'should extract URL path params along with query params', ->
+ router.match 'params/:one/:two/:three', 'null#null'
+ router.route '/params/123-foo/456-bar/3-three?referrer=mdp'
+ expect(_.isObject params).toBe true
+ expect(params.one).toBe '123-foo'
+ expect(params.two).toBe '456-bar'
+ expect(params.three).toBe '3-three'
+ expect(params.referrer).toBe 'mdp'
+
it 'should accept a regular expression as pattern', ->
router.match /^(\w+)\/(\w+)\/(\w+)$/, 'null#null'
router.route '/raw/regular/expression'

0 comments on commit c9fd2a9

Please sign in to comment.