From 6e7a5018663273b4e18027f5b7823e9eec0d61f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCrg=C3=BCn=20Day=C4=B1o=C4=9Flu?= Date: Wed, 31 Dec 2025 00:06:25 +0100 Subject: [PATCH] url: add fast path to getPathFromURL decoder PR-URL: https://github.com/nodejs/node/pull/60749 Reviewed-By: Yagiz Nizipli Reviewed-By: Aviv Keller --- lib/internal/url.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/internal/url.js b/lib/internal/url.js index bf128e7038..813208f39e 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -1463,7 +1463,10 @@ function getPathFromURLWin32(url) { } } pathname = SideEffectFreeRegExpPrototypeSymbolReplace(FORWARD_SLASH, pathname, '\\'); - pathname = decodeURIComponent(pathname); + // Fast-path: if there is no percent-encoding, avoid decodeURIComponent. + if (StringPrototypeIncludes(pathname, '%')) { + pathname = decodeURIComponent(pathname); + } if (hostname !== '') { // If hostname is set, then we have a UNC path // Pass the hostname through domainToUnicode just in case @@ -1569,7 +1572,8 @@ function getPathFromURLPosix(url) { } } } - return decodeURIComponent(pathname); + // Fast-path: if there is no percent-encoding, avoid decodeURIComponent. + return StringPrototypeIncludes(pathname, '%') ? decodeURIComponent(pathname) : pathname; } function getPathBufferFromURLPosix(url) {