« index
Coverage for /Users/yunong/workspace/node-restify/lib/plugins/pre/pre_path.js : 100%
41 lines |
41 run |
0 missing |
0 partial |
6 blocks |
6 blocks run |
0 blocks missing
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | // Copyright 2012 Mark Cavage, Inc. All rights reserved. ///--- Helpers /** * Cleans up sloppy URLs on the request object, like /foo////bar/// to /foo/bar. * */ function strip(path) { var cur; var next; var str = ''; for (var i = 0; i < path.length; i++) { cur = path.charAt(i); if (i !== path.length - 1) next = path.charAt(i + 1); if (cur === '/' && (next === '/' || (next === '?' && i > 0))) continue; str += cur; } return (str); } ///--- Exports module.exports = function sanitizePath(options) { options = options || {}; function _sanitizePath(req, res, next) { req.url = strip(req.url); next(); } return (_sanitizePath); }; |