diff --git a/index.js b/index.js index 42154ae..50e4f06 100644 --- a/index.js +++ b/index.js @@ -53,7 +53,7 @@ methods.forEach(function(method){ , self = this; this.namespace(path, function(){ - path = this._ns.join('/').replace(/\/\//g, '/').replace(/\/$/, '') || '/'; + path = 'string' != typeof path ? path : this._ns.join('/').replace(/\/\//g, '/').replace(/\/$/, '') || '/'; args.forEach(function(fn){ orig.call(self, path, fn); }); @@ -62,4 +62,4 @@ methods.forEach(function(method){ return this; }; }); -}); \ No newline at end of file +}); diff --git a/test/namespace.test.js b/test/namespace.test.js index 2aa7c98..385a0a8 100644 --- a/test/namespace.test.js +++ b/test/namespace.test.js @@ -106,4 +106,38 @@ describe('app.namespace(path, fn)', function(){ .get('/forum/23') .expect('23', done); }) + + it('should not die with regexes, but they ignore namespacing', function(done){ + var app = express(); + done = pending(3, done); + + app.get(/test\d\d\d/, function(req, res) { + res.send("GET test"); + }); + + app.namespace('/forum/:id', function(){ + + app.get('/', function(req, res){ + res.send('' + req.params.id); + }); + + app.get(/^\/(?!login$|account\/login$|logout$)(.*)/, function(req, res) { + res.send("crazy reg"); + }); + + }); + + request(app) + .get('/forum/23') + .expect('23', done); + + request(app) + .get('/test123') + .expect('GET test', done); + + request(app) + .get('/account/123') + .expect('crazy reg', done); + }) + }) \ No newline at end of file