Skip to content

Commit

Permalink
Handle multiple slashes between URL segements
Browse files Browse the repository at this point in the history
  • Loading branch information
mde committed Aug 25, 2012
1 parent f1fd030 commit c6d76fb
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
18 changes: 12 additions & 6 deletions lib/app.js
Expand Up @@ -387,7 +387,8 @@ var App = function () {
// Handle the requests
// ==================
geddy.server.addListener('request', function (req, resp) {
var reqObj
var reqUrl
, reqObj
, params
, urlParams
, method
Expand All @@ -411,6 +412,11 @@ var App = function () {
, accessTime = (new Date()).getTime()
, inFlighId;

// Sanitize URL; reduce multiple slashes to single slash
// TODO: Handle trailing slashes correctly, whatever
// 'correctly' means
reqUrl = req.url.replace(/\/{2,}/g, '/');

// Buffered request-obj -- buffer the request data,
// and pass this proxy object to the controller
reqObj = new Request(req);
Expand All @@ -427,7 +433,7 @@ var App = function () {
};

if (router) {
urlParams = url.parse(req.url, true).query;
urlParams = url.parse(reqUrl, true).query;

if (req.method.toUpperCase() == 'POST') {
// POSTs may be overridden by the _method param
Expand Down Expand Up @@ -476,7 +482,7 @@ var App = function () {
'- ' +
'- ' +
'[' + new Date(entry.accessTime) + '] ' +
'"' + entry.method + ' ' + req.url + ' ' +
'"' + entry.method + ' ' + reqUrl + ' ' +
req.httpVersion + '" ' +
stat + ' ' +
(resp._length || '-') + ' ' +
Expand All @@ -495,7 +501,7 @@ var App = function () {
}
});

params = router.first(req, method);
params = router.first(reqUrl, method);
}

if (params) {
Expand Down Expand Up @@ -619,7 +625,7 @@ var App = function () {
// Either static or 404
else {
// Get the path to the file
staticPath = geddy.config.staticFilePath + '/' + req.url;
staticPath = geddy.config.staticFilePath + reqUrl;
// Ignore querystring
staticPath = staticPath.split('?')[0];
// Decode path (e.g. %20)
Expand All @@ -630,7 +636,7 @@ var App = function () {
staticResp.sendFile(staticPath);
}
else {
err = new errors.NotFoundError(req.url + ' not found.');
err = new errors.NotFoundError(reqUrl + ' not found.');
errResp = new response.Response(resp);
errResp.send(err.message, err.statusCode,
{'Content-Type': 'text/html'});
Expand Down
4 changes: 2 additions & 2 deletions lib/routers/regexp_router.js
Expand Up @@ -126,11 +126,11 @@ var Router = function () {
*
* if there's no match, this will return false
*/
this.first = function (req, method) {
this.first = function (url, method) {
var routes = this.routes
, route
, ret = false
, path = req.url
, path = url
, notAllowed = false
, allowed = []
, err;
Expand Down

0 comments on commit c6d76fb

Please sign in to comment.