diff --git a/benchmark/url/url.js b/benchmark/url/url.js new file mode 100644 index 00000000000000..7116b94d60677c --- /dev/null +++ b/benchmark/url/url.js @@ -0,0 +1,26 @@ +var common = require('../common.js'); +var url = require('url'); + +var bench = common.createBenchmark(main, { + type: 'one two three four five'.split(' '), + n: [25e4] +}); + +function main(conf) { + var type = conf.type; + var n = conf.n | 0; + + var inputs = { + one: 'http://nodejs.org/docs/latest/api/url.html#url_url_format_urlobj', + two: 'http://blog.nodejs.org/', + three: 'https://encrypted.google.com/search?q=url&q=site:npmjs.org&hl=en', + four: 'javascript:alert("node is awesome");', + five: 'some.ran/dom/url.thing?oh=yes#whoo', + }; + var input = inputs[type] || ''; + + bench.start(); + for (var i = 0; i < n; i += 1) + url.parse(input); + bench.end(n); +} diff --git a/lib/url.js b/lib/url.js index 56b1be9328e2a0..c9d8b9df3957ac 100644 --- a/lib/url.js +++ b/lib/url.js @@ -319,11 +319,13 @@ Url.prototype.parse = function(url, parseQueryString, slashesDenoteHost) { // need to be. for (var i = 0, l = autoEscape.length; i < l; i++) { var ae = autoEscape[i]; - var esc = encodeURIComponent(ae); - if (esc === ae) { - esc = escape(ae); + if (rest.indexOf(ae) !== -1) { + var esc = encodeURIComponent(ae); + if (esc === ae) { + esc = escape(ae); + } + rest = rest.split(ae).join(esc); } - rest = rest.split(ae).join(esc); } }