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 2025-09-14 03:39:32 +03:00 committed by GitHub
parent 85db70b2cf
commit 1442023134
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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('');
}