url: replaced slice with at

PR-URL: https://github.com/nodejs/node/pull/59181
Reviewed-By: Jordan Harband <ljharb@gmail.com>
Reviewed-By: Zeyu "Alex" Yang <himself65@outlook.com>
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
Mikhail authored and Michaël Zasso committed 2025-09-24 09:03:35 +02:00
1 parent 9df91e59e1
commit 8b29bbca76
1 file changed
+4 -2
+4 -2
View File
@@ -22,10 +22,12 @@
'use strict';
const {
ArrayPrototypeJoin,
Boolean,
Int8Array,
ObjectAssign,
ObjectKeys,
StringPrototypeAt,
StringPrototypeCharCodeAt,
StringPrototypeIndexOf,
StringPrototypeReplaceAll,
@@ -923,7 +925,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 === '');
@@ -956,7 +958,7 @@ Url.prototype.resolveObject = function resolveObject(relative) {
srcPath.unshift('');
}
if (hasTrailingSlash && (srcPath.join('/').slice(-1) !== '/')) {
if (hasTrailingSlash && StringPrototypeAt(ArrayPrototypeJoin(srcPath, '/'), -1) !== '/') {
srcPath.push('');
}