From 5d3f74beafa9ce48049d23c80f5315d144925b19 Mon Sep 17 00:00:00 2001 From: Steven Date: Fri, 10 Oct 2025 21:43:04 -0400 Subject: [PATCH] doc: improve code snippet alternative of url.parse() using WHATWG URL --- doc/api/url.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/api/url.md b/doc/api/url.md index 8bde8f1161ca70..bdb544a95b9bec 100644 --- a/doc/api/url.md +++ b/doc/api/url.md @@ -1853,7 +1853,7 @@ input. CVEs are not issued for `url.parse()` vulnerabilities. Use the function getURL(req) { const proto = req.headers['x-forwarded-proto'] || 'https'; const host = req.headers['x-forwarded-host'] || req.headers.host || 'example.com'; - return new URL(req.url || '/', `${proto}://${host}`); + return new URL(`${proto}://${host}${req.url || '/'}`); } ``` @@ -1863,7 +1863,7 @@ use the example below: ```js function getURL(req) { - return new URL(req.url || '/', 'https://example.com'); + return new URL(`https://example.com${req.url || '/'}`); } ```