Skip to content
This repository has been archived by the owner on Jun 15, 2023. It is now read-only.

Commit

Permalink
Fix URL matching with query params
Browse files Browse the repository at this point in the history
  • Loading branch information
mdp committed Jun 20, 2012
1 parent 03620e6 commit c9fd2a9
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/chaplin/lib/route.coffee
Expand Up @@ -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) ->
Expand Down
9 changes: 9 additions & 0 deletions test/spec/router_spec.coffee
Expand Up @@ -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'
Expand Down

0 comments on commit c9fd2a9

Please sign in to comment.