Skip to content

Commit 9446832

Browse files
styfleaduh95
authored andcommitted
doc: improve code snippet alternative of url.parse() using WHATWG URL
PR-URL: #60209 Reviewed-By: Yagiz Nizipli <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent 987a023 commit 9446832

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

doc/api/url.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1847,7 +1847,7 @@ input. CVEs are not issued for `url.parse()` vulnerabilities. Use the
18471847
function getURL(req) {
18481848
const proto = req.headers['x-forwarded-proto'] || 'https';
18491849
const host = req.headers['x-forwarded-host'] || req.headers.host || 'example.com';
1850-
return new URL(req.url || '/', `${proto}://${host}`);
1850+
return new URL(`${proto}://${host}${req.url || '/'}`);
18511851
}
18521852
```
18531853
@@ -1857,7 +1857,7 @@ use the example below:
18571857
18581858
```js
18591859
function getURL(req) {
1860-
return new URL(req.url || '/', 'https://example.com');
1860+
return new URL(`https://example.com${req.url || '/'}`);
18611861
}
18621862
```
18631863

0 commit comments

Comments
 (0)