summaryrefslogtreecommitdiff
path: root/lib/url.js
AgeCommit message (Collapse)Author
2017-03-10meta: restore original copyright headerJames M Snell
A prior io.js era commit inappropriately removed the original copyright statements from the source. This restores those in any files still remaining from that edit. Ref: https://github.com/nodejs/TSC/issues/174 Ref: https://github.com/nodejs/node/pull/10599 PR-URL: https://github.com/nodejs/node/pull/10155 Note: This PR was required, reviewed-by and approved by the Node.js Foundation Legal Committee and the TSC. There is no `Approved-By:` meta data.
2017-03-04url: use `hasIntl` instead of `try-catch`Daijiro Wachi
Like the other internal modules, we should use `process.binding('config').hasIntl` instead of `try-catch` to make sure `icu` is bonded or not. PR-URL: https://github.com/nodejs/node/pull/11571 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jackson Tian <shyvo1987@gmail.com>
2017-02-28src: do not ignore IDNA conversion errorTimothy Gu
Old behavior can be restored using a special `lenient` mode, as used in the legacy URL parser. PR-URL: https://github.com/nodejs/node/pull/11549 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2017-02-14url: fix surrogate handling in encodeAuth()Timothy Gu
Also factor out common parts in querystring and url. PR-URL: https://github.com/nodejs/node/pull/11161 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
2017-02-11url: fix error message of url.formatDavidCai
PR-URL: https://github.com/nodejs/node/pull/11162 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2017-02-02url: extend url.format to support WHATWG URLJames M Snell
Removes the non-standard options on WHATWG URL toString and extends the existing url.format() API to support customizable serialization of the WHATWG URL object. This does not yet include the documentation updates because the documentation for the new WHATWG URL object has not yet landed. Example: ```js const url = require('url'); const URL = url.URL; const myURL = new URL('http://example.org/?a=b#c'); const str = url.format(myURL, {fragment: false, search: false}); console.log(str); // Prints: http://example.org/ ``` PR-URL: https://github.com/nodejs/node/pull/10857 Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
2017-01-27url: stop exporting originFor()Timothy Gu
PR-URL: https://github.com/nodejs/node/pull/10955 Fixes: https://github.com/nodejs/node/issues/10800 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
2017-01-22url: export URLSearchParamsTimothy Gu
Fixes: #10761
2016-12-30url: move originFor, domainToAscii and domainToUnicodeJames M Snell
Move non-standard methods to `url` module instead of exposing as static methods on the `URL` object. PR-URL: https://github.com/nodejs/node/pull/10512 Reviewed-By: Italo A. Casas <me@italoacasas.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
2016-12-24url: do not truncate long hostnamesJunshu Okamoto
Currently, around line 417 lib/url.js is truncating hostname and put the rest of hostname to the path if hostname length after `.` is equal or more than 63. This behavior is different from browser behavior. I changed the code so that it doesn’t truncate. I also added the test example which has more than 63 length in after `.` in hostname in test url. PR-URL: https://github.com/nodejs/node/pull/9292 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
2016-12-22tools: enforce linebreak after ternary operatorsMichaël Zasso
This is to be consistent with the other operators and helps understanding the context when the code is grepped. PR-URL: https://github.com/nodejs/node/pull/10213 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Teddy Katz <teddy.katz@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2016-12-06url: add a got host pattern in url.jsAxel Monroy
Add a hostPattern variable for readable purposes PR-URL: https://github.com/nodejs/node/pull/9653 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Brian White <mscdex@mscdex.net>
2016-12-05test,url: improve escaping in url.parsejoyeecheung
- rename variables in autoEscapeStr so they are easier to understand - comment the escaping algorithm - increase coverage for autoEscapeStr PR-URL: https://github.com/nodejs/node/pull/10083 Reviewed-By: Anna Henningsen <anna@addaleax.net>
2016-11-23lib,tools: remove unneeded escaping of /Prince J Wesley
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/9591 Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
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>