diff --git a/lib/route66.coffee b/lib/route66.coffee index dca661d..8612bc2 100644 --- a/lib/route66.coffee +++ b/lib/route66.coffee @@ -44,7 +44,7 @@ Route66.addRoute = (method, route, functions) -> # generic method for adding rou Route66.routes[method].push route: route - regex: new RegExp('^' + route.replace(/\//g, '\\/').replace(/\:([A-Za-z_]+)(\?)?\/?/g, '$2([A-Za-z0-9._-]+)$2') + '\\/?$') # making RegExp from string + regex: new RegExp('^' + route.replace(/\//g, '\\/').replace(/\:([A-Za-z_]+)(\?)?\/?/g, '$2([A-Za-z0-9@._-]+)$2') + '\\/?$') # making RegExp from string params: params functions: if functions instanceof Array then functions else toArray(functions).slice 1 diff --git a/lib/route66.js b/lib/route66.js index 5242351..abd60f0 100644 --- a/lib/route66.js +++ b/lib/route66.js @@ -61,7 +61,7 @@ Route66.addRoute = function(method, route, functions) { } Route66.routes[method].push({ route: route, - regex: new RegExp('^' + route.replace(/\//g, '\\/').replace(/\:([A-Za-z_]+)(\?)?\/?/g, '$2([A-Za-z0-9._-]+)$2') + '\\/?$'), + regex: new RegExp('^' + route.replace(/\//g, '\\/').replace(/\:([A-Za-z_]+)(\?)?\/?/g, '$2([A-Za-z0-9@._-]+)$2') + '\\/?$'), params: params, functions: functions instanceof Array ? functions : toArray(functions).slice(1) }); diff --git a/package.json b/package.json index 75ff652..ed005b4 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "route66", - "version": "0.2.3", + "version": "0.2.4", "author": "Vadim Demedes ", "description": "Routing functionality/middleware for Connect 2.0", "main": "./index.js", diff --git a/test/route66.test.coffee b/test/route66.test.coffee index 19fc241..a506e9b 100644 --- a/test/route66.test.coffee +++ b/test/route66.test.coffee @@ -25,6 +25,9 @@ router.post '/', (req, res) -> router.get '/:first/:second', (req, res) -> res.end 'Only parameters' +router.get '/:email', (req, res) -> + res.end 'Got an email!' + router.notFound (req, res) -> res.end "Not found." @@ -76,11 +79,16 @@ describe 'Route66', -> method: 'GET' , (err, res) -> res.body.should.equal 'Only parameters' - done() + request + url: 'http://localhost:8080/test@test.com' + method: 'GET' + , (err, res) -> + res.body.should.equal 'Got an email!' + done() it 'should respond with an error', (done) -> request - url: 'http://localhost:8080/error' + url: 'http://localhost:8080/one/two/error' method: 'GET' , (err, res) -> res.body.should.equal 'Not found.'