Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions doc/api/deprecations.md
Original file line number Diff line number Diff line change
Expand Up @@ -3776,6 +3776,9 @@ Type: Application (non-`node_modules` code only)
have security implications. Use the [WHATWG URL API][] instead. CVEs are not
issued for `url.parse()` vulnerabilities.

Passing a string argument to [`url.format()`][] invokes `url.parse()`
internally, and is therefore also covered by this deprecation.

### DEP0170: Invalid port when using `url.parse()`

<!-- YAML
Expand Down
47 changes: 44 additions & 3 deletions doc/api/url.md
Original file line number Diff line number Diff line change
Expand Up @@ -1739,9 +1739,8 @@
times.
-->

* `urlObject` {Object|string} A URL object (as returned by `url.parse()` or
constructed otherwise). If a string, it is converted to an object by passing
it to `url.parse()`.
* `urlObject` {Object} A URL object (as returned by `url.parse()` or
constructed otherwise).

The `url.format()` method returns a formatted URL string derived from
`urlObject`.
Expand Down Expand Up @@ -1822,6 +1821,48 @@
npx codemod@latest @nodejs/node-url-to-whatwg-url
```

### `url.format(urlString)`

<!-- YAML
added: v0.1.25
changes:
- version:
- v24.0.0
pr-url: https://github.com/nodejs/node/pull/55017

Check warning on line 1831 in doc/api/url.md

View workflow job for this annotation

GitHub Actions / lint-pr-url

pr-url doesn't match the URL of the current PR.
description: Application deprecation.
-->

> Stability: 0 - Deprecated: Use the WHATWG URL API instead.

* `urlString` {string} A string that will be passed to `url.parse()` and then
formatted.

`url.format(urlString)` is shorthand for `url.format(url.parse(urlString))`.

Because it invokes the deprecated [`url.parse()`][], passing a string argument
to `url.format()` is itself deprecated.

Canonicalizing a URL string can be performed using the WHATWG URL API, by
constructing a new URL object and calling [`url.toString()`][].

```mjs
import { URL } from 'node:url';

const unformatted = 'http://[fe80:0:0:0:0:0:0:1]:/a/b?a=b#abc';
const formatted = new URL(unformatted).toString();

console.log(formatted); // Prints: http://[fe80::1]/a/b?a=b#abc
```

```cjs
const { URL } = require('node:url');

const unformatted = 'http://[fe80:0:0:0:0:0:0:1]:/a/b?a=b#abc';
const formatted = new URL(unformatted).toString();

console.log(formatted); // Prints: http://[fe80::1]/a/b?a=b#abc
```

### `url.parse(urlString[, parseQueryString[, slashesDenoteHost]])`

<!-- YAML
Expand Down
Loading