Skip to content

Loading…

Connect adds a trailing slash to req.url for the remaining routes if the route is equal to req.url #523

Closed
wants to merge 2 commits into from

2 participants

@tellnes

No description provided.

@tj
Sencha Labs member
tj commented

merged thanks!

@tj tj closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Mar 30, 2012
  1. @tellnes
  2. @tellnes

    remove trailing flash

    tellnes committed
This page is out of date. Refresh to see the latest.
Showing with 27 additions and 1 deletion.
  1. +11 −1 lib/proto.js
  2. +16 −0 test/mounting.js
View
12 lib/proto.js
@@ -103,10 +103,17 @@ app.handle = function(req, res, out) {
var stack = this.stack
, fqdn = ~req.url.indexOf('://')
, removed = ''
+ , slashAdded = false
, index = 0;
function next(err) {
var layer, path, status, c;
+
+ if (slashAdded) {
+ req.url = req.url.substr(1);
+ slashAdded = false;
+ }
+
req.url = removed + req.url;
req.originalUrl = req.originalUrl || req.url;
removed = '';
@@ -166,7 +173,10 @@ app.handle = function(req, res, out) {
req.url = req.url.substr(removed.length);
// Ensure leading slash
- if (!fqdn && '/' != req.url[0]) req.url = '/' + req.url;
+ if (!fqdn && '/' != req.url[0]) {
+ req.url = '/' + req.url;
+ slashAdded = true;
+ }
debug('%s', layer.handle.name || 'anonymous');
var arity = layer.handle.length;
View
16 test/mounting.js
@@ -73,6 +73,22 @@ describe('app.use()', function(){
blog.route.should.equal('/blog');
admin.route.should.equal('/admin');
})
+
+ it('should not add trailing slash', function(done) {
+ var app = connect();
+
+ app.use('/admin', function(req, res, next) {
+ next();
+ });
+
+ app.use(function(req, res, next) {
+ res.end(req.url);
+ });
+
+ app.request()
+ .get('/admin')
+ .expect('/admin', done);
+ })
})
describe('with a node app', function(){
Something went wrong with that request. Please try again.