« index
Coverage for /Users/yunong/workspace/node-restify/lib/utils.js : 93%
46 lines |
43 run |
3 missing |
1 partial |
5 blocks |
3 blocks run |
2 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 42 43 44 45 46 | // Copyright 2012 Mark Cavage, Inc. All rights reserved. var assert = require('assert-plus'); /** * Cleans up sloppy URL paths, like /foo////bar/// to /foo/bar. * * @param {String} path the HTTP resource path. * @return {String} Cleaned up form of path. */ function sanitizePath(path) { assert.ok(path); // Be nice like apache and strip out any //my//foo//bar///blah path = path.replace(/\/\/+/g, '/'); // Kill a trailing '/' if (path.lastIndexOf('/') === (path.length - 1) && path.length > 1) path = path.substr(0, path.length - 1); return (path); } /** * Return a shallow copy of the given object; */ function shallowCopy(obj) { if (!obj) { return (obj); } var copy = {}; Object.keys(obj).forEach(function (k) { copy[k] = obj[k]; }); return (copy); } ///--- Exports module.exports = { sanitizePath: sanitizePath, shallowCopy: shallowCopy }; |