From 14420231347c96410bd045cd6a68e96755dbd023 Mon Sep 17 00:00:00 2001 From: Mikhail Date: Sun, 14 Sep 2025 03:39:32 +0300 Subject: [PATCH] url: replaced slice with at PR-URL: https://github.com/nodejs/node/pull/59181 Reviewed-By: Jordan Harband Reviewed-By: Zeyu "Alex" Yang Reviewed-By: Daniel Lemire Reviewed-By: Luigi Pinca Reviewed-By: Ruben Bridgewater --- lib/url.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/url.js b/lib/url.js index 6331188bfe..7248c9c277 100644 --- a/lib/url.js +++ b/lib/url.js @@ -22,10 +22,12 @@ 'use strict'; const { + ArrayPrototypeJoin, Boolean, Int8Array, ObjectAssign, ObjectKeys, + StringPrototypeAt, StringPrototypeCharCodeAt, StringPrototypeIndexOf, StringPrototypeReplaceAll, @@ -919,7 +921,7 @@ Url.prototype.resolveObject = function resolveObject(relative) { // If a url ENDs in . or .., then it must get a trailing slash. // however, if it ends in anything else non-slashy, // then it must NOT get a trailing slash. - let last = srcPath.slice(-1)[0]; + let last = srcPath[srcPath.length - 1]; const hasTrailingSlash = ( ((result.host || relative.host || srcPath.length > 1) && (last === '.' || last === '..')) || last === ''); @@ -952,7 +954,7 @@ Url.prototype.resolveObject = function resolveObject(relative) { srcPath.unshift(''); } - if (hasTrailingSlash && (srcPath.join('/').slice(-1) !== '/')) { + if (hasTrailingSlash && StringPrototypeAt(ArrayPrototypeJoin(srcPath, '/'), -1) !== '/') { srcPath.push(''); }