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