From 3e2e563f68472880b4290b5cfdb0e8312c2d8066 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Tue, 22 Oct 2013 13:34:06 -0400 Subject: [PATCH] Fix mounted path splitting to ignore search part This fixes the mounting to ignore what looks like FQDNs in the search part of the URL, which fixes URL mangling when passing plain FQDNs in the search part. --- lib/proto.js | 4 +++- test/mounting.js | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/proto.js b/lib/proto.js index 9eca15cb4..e0358b20f 100644 --- a/lib/proto.js +++ b/lib/proto.js @@ -100,7 +100,9 @@ app.use = function(route, fn){ app.handle = function(req, res, out) { var stack = this.stack - , fqdn = 1 + req.url.indexOf('://') + , search = 1 + req.url.indexOf('?') + , pathlength = search ? search - 1 : req.url.length + , fqdn = 1 + req.url.substr(0, pathlength).indexOf('://') , protohost = fqdn ? req.url.substr(0, req.url.indexOf('/', 2 + fqdn)) : '' , removed = '' , slashAdded = false diff --git a/test/mounting.js b/test/mounting.js index 22fd0a4bd..a0a8530b3 100644 --- a/test/mounting.js +++ b/test/mounting.js @@ -49,6 +49,18 @@ describe('app.use()', function(){ .expect('/post/1', done); }) + it('should ignore FQDN in search', function (done) { + var app = connect(); + + app.use('/proxy', function (req, res) { + res.end(req.url); + }); + + app.request() + .get('/proxy?url=http://example.com/blog/post/1') + .expect('/?url=http://example.com/blog/post/1', done); + }); + it('should adjust FQDN req.url', function(done){ var app = connect();