summaryrefslogtreecommitdiff
path: root/lib/url.js
AgeCommit message (Collapse)Author
2016-11-09lib,test: remove unneeded escaping of /Rich Trott
The `/` character does not need to be escaped when occurring inside a character class in a regular expression. Remove such instances of escaping in the code base. PR-URL: https://github.com/nodejs/node/pull/9485 Reviewed-By: Prince John Wesley <princejohnwesley@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io>
2016-10-11url: adding WHATWG URL supportJames M Snell
Implements WHATWG URL support. Example: ``` var u = new url.URL('http://example.org'); ``` Currently passing all WHATWG url parsing tests and all but two of the setter tests. The two setter tests are intentionally skipped for now but will be revisited. PR-URL: https://github.com/nodejs/node/pull/7448 Reviewed-By: Ilkka Myller <ilkka.myller@nodefield.com>
2016-09-11url: fix off-by-one error in loop handling dotsLuigi Pinca
Fixes an error where a loop, used to traverse an array of length `n`, ran `n + 1` times instead of `n`. PR-URL: https://github.com/nodejs/node/pull/8420 Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2016-08-24url: keep auth in `url.resolve()` if host matchesIlkka Myller
Fixes: https://github.com/nodejs/node/issues/8165 PR-URL: https://github.com/nodejs/node/pull/8215 Reviewed-By: James M Snell <jasnell@gmail.com>
2016-08-23url: fix inconsistent port in url.resolveObjectIlkka Myller
This commit fixes bug where url.resolveObject returns conflicting host and port values. Fixes: https://github.com/nodejs/node/issues/8213 PR-URL: https://github.com/nodejs/node/pull/8214 Reviewed-By: James M Snell <jasnell@gmail.com>
2016-08-18url: `url.format()` encodes all `#` in `search`Ilkka Myller
This commit fixes an error where only the first occurrence of `#` in `search` parameter is URL encoded, and subsequent occurrences are not. Also added a test for the case. Fixes: https://github.com/nodejs/node/issues/8064 PR-URL: https://github.com/nodejs/node/pull/8072 Reviewed-By: James M Snell <jasnell@gmail.com>
2016-06-29net: use icu's punycode implementationJames M Snell
ICU has a punycode implementation built in. Use it instead of the javascript implementation because it's much faster. PR-URL: https://github.com/nodejs/node/pull/7355 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2016-06-16url: return valid file: urls fom url.format()Rich Trott
`file:` URLs that do not start with `file://` are invalid. Browsers convert `file:/etc/passwd` to `file:///etc/passwd`. This is also what the docs indicate we are doing, but we're not. PR-URL: https://github.com/nodejs/node/pull/7234 Fixes: https://github.com/nodejs/node/issues/3361 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Brian White <mscdex@mscdex.net>
2016-04-25url: drop auth in `url.resolve()` if host changesAlex Kocharin
Fixes: https://github.com/nodejs/node/issues/1435 PR-URL: https://github.com/nodejs/node/pull/1480 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
2016-04-20url: use "empty" object for empty query stringsBrian White
This makes things consistent with the way that the querystring module creates parsed results. PR-URL: https://github.com/nodejs/node/pull/6289 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michaël Zasso <mic.besace@gmail.com> Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Minwoo Jung <jmwsoft@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2016-02-29url: group slashed protocols by protocol namenettofarah
Reorder slashed protocols so they are grouped by protocol name. This is done so it doesn't look like we're duplicating protocol names at the bottom of the list. PR-URL: https://github.com/nodejs/node/pull/5380 Reviewed-By: Evan Lucas <evanlucas@me.com>
2016-02-27url: fix off-by-one error with parse()Brian White
Fixes: https://github.com/nodejs/node/issues/5393 PR-URL: https://github.com/nodejs/node/pull/5394 Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Rod Vagg <rod@vagg.org> Reviewed-By: Evan Lucas <evanlucas@me.com>
2016-02-18url: fix lint and deopt issuesBrian White
The deopt issues arose from the use of const in specific situations that v8 does not fully support yet. Fixes: https://github.com/nodejs/node/issues/5299 PR-URL: https://github.com/nodejs/node/pull/5300 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
2016-02-18url: improve url.parse() performanceBrian White
This commit improves url.parse() performance by 50-210% with the existing url/url-parse benchmarks. Also, the optimizations made in url.format() result in a 40% increase in performance for url.resolve(). Some optimization strategies used in this commit include: * Combining multiple searches on the same string into a single loop * Avoiding unnecessary string.split() and array.join() * Minimizing creation of temporary strings * Using a faster alternative to encodeURIComponent, borrowed from the querystring module PR-URL: https://github.com/nodejs/node/pull/4892 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ryan Graham <r.m.graham@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
2016-01-27url: change scoping of variables with letKári Tristan Helgason
Also changes some `var`s to `const` as they never change. PR-URL: https://github.com/nodejs/node/pull/4867 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-01-13lib: fix style issues after eslint updateMichaël Zasso
With an indentation style of two spaces, it is not possible to indent multiline variable declarations by four spaces. Instead, the var keyword is used on every new line. Use const instead of var where applicable for changed lines. PR-URL: https://github.com/nodejs/io.js/pull/2286 Reviewed-By: Roman Reiss <me@silverwind.io>
2015-12-30doc: fix spelling error in lib/url.js commentNik Nyby
PR-URL: https://github.com/nodejs/node/pull/4390 Reviewed-By: Stephen Belanger <admin@stephenbelanger.com> Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2015-11-09lib: Consistent error messages in all modulesmicnic
This commit fixes some error messages that are not consistent with some general rules which most of the error messages follow. PR-URL: https://github.com/nodejs/node/pull/3374 Reviewed-By: Roman Reiss <me@silverwind.io>
2015-08-05doc: multiple documentation updates cherry picked from v0.12James M Snell
* doc: improve http.abort description * doc: mention that mode is ignored if file exists * docs: Fix default options for fs.createWriteStream() * Documentation update about Buffer initialization * doc: add a note about readable in flowing mode * doc: Document http.request protocol option * doc, comments: Grammar and spelling fixes * updated documentation for fs.createReadStream * Update child_process.markdown, spelling * doc: Clarified read method with specified size argument. * docs:events clarify emitter.listener() behavior * doc: two minor stream doc improvements * doc: clarify Readable._read and Readable.push * doc: stream.unshift does not reset reading state * doc: readable event clarification * doc: additional refinement to readable event Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noorduis <ben@strongloop.com> PR-URL: https://github.com/nodejs/io.js/pull/2302
2015-06-30url: fix typo in commentRich Trott
PR-URL: https://github.com/nodejs/io.js/pull/2071 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-05-09lib: fix eslint stylesYosuke Furukawa
PR-URL: https://github.com/iojs/io.js/pull/1539 Fixes: https://github.com/iojs/io.js/issues/1253 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com> Reviewed-By: Johan Bergström <bugs@bergstroem.nu> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
2015-05-03Revert "url: significantly improve the performance of the url module"Rod Vagg
This reverts commit 3fd7fc429c394059113432312ed19decbafd8fc4. It was agreed that this change contained too much potential ecosystem breakage, particularly around the inability to `delete` properties off a `Url` object. It may be re-introduced for a later release, along with better work on ecosystem compatibility. PR-URL: https://github.com/iojs/io.js/pull/1602 Reviewed-By: Mikeal Rogers <mikeal.rogers@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Forrest L Norvell <forrest@npmjs.com> Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com> Reviewed-By: Isaac Z. Schlueter <i@izs.me> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-05-03Revert "url: delete href cache on all setter code paths"Rod Vagg
This reverts commit dbdd81a91bdce4cc59163e3be752dc3c53491987. It was agreed that this change contained too much potential ecosystem breakage, particularly around the inability to `delete` properties off a `Url` object. It may be re-introduced for a later release, along with better work on ecosystem compatibility. PR-URL: #1602 Reviewed-By: Mikeal Rogers <mikeal.rogers@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Forrest L Norvell <forrest@npmjs.com> Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com> Reviewed-By: Isaac Z. Schlueter <i@izs.me> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-05-03Revert "url: fix treatment of some values as non-empty"Rod Vagg
This reverts commit 66877216bd833face753d9a5d573ad477895d880. It was agreed that this change contained too much potential ecosystem breakage, particularly around the inability to `delete` properties off a `Url` object. It may be re-introduced for a later release, along with better work on ecosystem compatibility. PR-URL: #1602 Reviewed-By: Mikeal Rogers <mikeal.rogers@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Forrest L Norvell <forrest@npmjs.com> Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com> Reviewed-By: Isaac Z. Schlueter <i@izs.me> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com>
2015-05-03url: fix treatment of some values as non-emptyPetka Antonov
In addition to null, undefined and the empty string are treated as empty (removing the component from the url). The string '#' is treated same as empty values when setting .hash. The string '?' is treated same as empty values when setting .search. PR-URL: https://github.com/iojs/io.js/pull/1589 Fixes: https://github.com/iojs/io.js/issues/1588 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-05-03url: delete href cache on all setter code pathsPetka Antonov
PR-URL: https://github.com/iojs/io.js/pull/1589 Fixes: https://github.com/iojs/io.js/issues/1588 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-05-01url: significantly improve the performance of the url modulePetka Antonov
(landed by @rvagg) PR-URL: https://github.com/iojs/io.js/pull/1561 Reviewed-By: Domenic Denicola <domenic@domenicdenicola.com> Reviewed-By: Rod Vagg <rod@vagg.org>
2015-04-04url: fix resolving from non-file to file URLs.Jeffrey Jagoda
When resolving a reference URL with the 'file' scheme an no host against a base URL without the 'file' scheme, the first path element of the reference URL is used as the host for the target URL. This results in an invalid target URL. This change makes an exception for file URLs so that the host is not mangled during URL resolution. PR-URL: https://github.com/iojs/io.js/pull/1277 Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Petka Antonov <petka_antonov@hotmail.com>
2015-03-08url: remove redundant assignment in url.parseAlex Kocharin
PR-URL: https://github.com/iojs/io.js/pull/1095 Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Nicu Micleușanu <micnic90@gmail.com>
2015-03-04url: throw for invalid values to url.formatChristian Tellnes
`'use strict'` changes the behavior for `Function.prototype.call` when the context is `undefined`. In earlier versions of node the value `undefined` would make `url.format` look for fields in the global scope. The docs states that `url.format` takes a parsed URL object and returns a formatted URL string. So with this change it will now throw for other values. The exception is if the input is a string. Then it will call `url.parse` on the string and then format it. The reason for that is that you can call `url.format` on strings to clean up potentially wonky urls. Fixes: https://github.com/iojs/io.js/issues/1033 PR-URL: https://github.com/iojs/io.js/pull/1036 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net> Reviewed-By: Julian Duque <julianduquej@gmail.com>
2015-02-13url: reslove urls with . and ..Amir Saboury
'.' and '..' are directory specs and resolving urls with or without the hostname with '.' and '..' should add a trailing slash to the end of the url. Fixes: https://github.com/joyent/node/issues/8992 PR-URL: https://github.com/iojs/io.js/pull/278 Reviewed-By: Trevor Norris <trev.norris@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2015-01-31lib: reduce util.is*() usagecjihrig
Many of the util.is*() methods used to check data types simply compare against a single value or the result of typeof. This commit replaces calls to these methods with equivalent checks. This commit does not touch calls to the more complex methods (isRegExp(), isDate(), etc.). Fixes: https://github.com/iojs/io.js/issues/607 PR-URL: https://github.com/iojs/io.js/pull/647 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-21lib: use const to define constantscjihrig
This commit replaces a number of var statements throughout the lib code with const statements. PR-URL: https://github.com/iojs/io.js/pull/541 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-12Remove excessive copyright/license boilerplateisaacs
The copyright and license notice is already in the LICENSE file. There is no justifiable reason to also require that it be included in every file, since the individual files are not individually distributed except as part of the entire package.
2015-01-12Revert "url: support `path` for url.format"Ben Noordhuis
This reverts commit d312b6d15c69cf4c438ed7d884e6396c481a57f6. Reverted for breaking `npm install` with git+ssh URLs. Conflicts: doc/api/url.markdown Fixes: https://github.com/iojs/io.js/issues/295 PR-URL: https://github.com/iojs/io.js/pull/303 Reviewed-By: Rod Vagg <rod@vagg.org>
2015-01-12url: fix parsing of ssh urlsEvan Lucas
Fix regression introduced in 61204720361824881aefd64f5bccda7d7be6617a that broke parsing of some ssh: urls. An example url is ssh://git@github.com:npm/npm.git PR-URL: https://github.com/iojs/io.js/pull/299 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2015-01-05Merge remote-tracking branch 'joyent/v0.12' into v1.xBen Noordhuis
I was originally going to do this after the v0.11.15 release, but as that release is three weeks overdue now, I decided not to wait any longer; we don't want the delta to get too big. Conflicts: lib/net.js test/simple/simple.status PR-URL: https://github.com/iojs/io.js/pull/236 Reviewed-By: Bert Belder <bertbelder@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-12-30url: improve parsing speedCGavrila
The url.parse() function now checks whether an escapable character is in the URL before trying to escape it. PR-URL: https://github.com/joyent/node/pull/8638 [trev.norris@gmail.com: Switch to use continue instead of if] Signed-off-by: Trevor Norris <trev.norris@gmail.com>
2014-12-20lib: micro-optimize url.resolve()Ben Noordhuis
Replace the call to Array#splice() with a faster open-coded version that creates less garbage. Add a new benchmark to prove it. With the change applied, it scores about 5% higher and that is nothing to sneeze at. PR-URL: https://github.com/iojs/io.js/pull/184 Reviewed-By: Chris Dickinson <christopher.s.dickinson@gmail.com>
2014-12-09url: change hostname regex to negate invalid charsJonathan Johnson
Regarding joyent/node#8520 This changes hostname validation from a whitelist regex approach to a blacklist regex approach as described in https://url.spec.whatwg.org/#host-parsing. url.parse misinterpreted `https://good.com+.evil.org/` as `https://good.com/+.evil.org/`. If we use url.parse to check the validity of the hostname, the test passes, but in the browser the user is redirected to the evil.org website.
2014-12-02url: change hostname regex to negate invalid charsJonathan Johnson
Regarding joyent/node#8520 This changes hostname validation from a whitelist regex approach to a blacklist regex approach as described in https://url.spec.whatwg.org/#host-parsing. url.parse misinterpreted `https://good.com+.evil.org/` as `https://good.com/+.evil.org/`. If we use url.parse to check the validity of the hostname, the test passes, but in the browser the user is redirected to the evil.org website.
2014-12-02url: support `path` for url.formatYazhong Liu
this adds support for a "path" field that overrides "query", "search", and "pathname" if given. Fixes: https://github.com/joyent/node/issues/8722 PR-URL: https://github.com/joyent/node/pull/8755 Reviewed-by: Chris Dickinson <christopher.s.dickinson@gmail.com>
2014-12-02url: support `path` for url.formatYazhong Liu
this adds support for a "path" field that overrides "query", "search", and "pathname" if given. Fixes: https://github.com/joyent/node/issues/8722 PR-URL: https://github.com/joyent/node/pull/8755 Reviewed-by: Chris Dickinson <christopher.s.dickinson@gmail.com>
2014-11-22lib: turn on strict modeBen Noordhuis
Turn on strict mode for the files in the lib/ directory. It helps catch bugs and can have a positive effect on performance. PR-URL: https://github.com/node-forward/node/pull/64 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Fedor Indutny <fedor@indutny.com>
2014-10-08src: fix jslint warningTrevor Norris
Signed-off-by: Trevor Norris <trev.norris@gmail.com>
2014-10-06url: fixed encoding for slash switching emulation.Evan Rutledge Borden
Fixes: https://github.com/joyent/node/issues/8458 Reviewed-by: Trevor Norris <trev.norris@gmail.com> Reviewed-by: Chris Dickinson <christopher.s.dickinson@gmail.com>
2014-10-01url: make query() consistentGabriel Wicke
Match the behavior of the slow path by setting url.query to an empty object when the url contains no query, but query parsing is requested. Also add a test for this case, and update the documents to clearly reflect this behavior. Fixes: https://github.com/joyent/node/issues/8332 Reviewed-by: Trevor Norris <trev.norris@gmail.com>
2014-09-16Merge remote-tracking branch 'upstream/v0.10' into v0.12Timothy J Fontaine
Conflicts: ChangeLog deps/v8/src/hydrogen.cc lib/http.js lib/querystring.js src/node_crypto.cc src/node_version.h test/simple/test-querystring.js
2014-09-05lib: improved forEach object performanceMajid Arif Siddiqui
Reviewed-by: Trevor Norris <trev.norris@gmail.com>
2014-08-27url: Add support for RFC 3490 separatorsMathias Bynens
There is no need to split the host by hand in `url.js` – Punycode.js takes care of it anyway. This not only simplifies the code, but also adds support for RFC 3490 separators (i.e. not just U+002E, but U+3002, U+FF0E, and U+FF61 as well). Closes #6055. Reviewed-By: Fedor Indutny <fedor@indutny.com>