Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
4c6f73c
url: improve performance of the format function
puskin May 3, 2025
94c720c
util: add internal `assignFunctionName()` function
LiviaMedeiros Apr 17, 2025
7dabf07
child_process: give names to promisified `exec()` and `execFile()`
LiviaMedeiros Apr 17, 2025
8f1aee9
http2: give name to promisified `connect()`
LiviaMedeiros Apr 17, 2025
62dbd36
doc: update return types for eventNames method in EventEmitter
y-hsgw May 4, 2025
629a954
repl: add possibility to edit multiline commands while adding them
puskin Apr 23, 2025
714b706
repl: add proper vertical cursor movements
puskin May 1, 2025
6544663
test: reduce flakiness in test-heapdump-http2
joyeecheung May 5, 2025
2874542
test_runner: unify --require and --import behavior when isolation none
pmarchini May 6, 2025
7e4453f
build: escape > metachar in vcbuild
Flarna May 6, 2025
4c967b7
buffer: use constexpr where possible
anonrig May 6, 2025
c815f29
src: remove NonCopyableMaybe
tniessen May 6, 2025
b33e8d2
async_hooks: ensure AsyncLocalStore instances work isolated
Flarna May 6, 2025
2e54653
build: use FILE_OFFSET_BITS=64 esp. on 32-bit arch
RafaelGSS Apr 30, 2025
90d4c11
deps: update amaro to 0.5.3
nodejs-github-bot May 7, 2025
a0ca155
deps: update llhttp to 9.3.0
indutny May 7, 2025
6403aa4
crypto: merge CipherBase.initiv into constructor
tniessen May 7, 2025
09a85fd
test: skip test-buffer-tostring-rangeerror when low on memory
BridgeAR May 7, 2025
eb4f130
test: remove Float16Array flag
LiviaMedeiros May 7, 2025
908782b
sqlite: add build option to build without sqlite
mhdawson Apr 29, 2025
e75ecf8
Revert "deps: disable V8 concurrent sparkplug compilation"
targos May 6, 2025
e3193ee
Revert "deps: always define V8_EXPORT_PRIVATE as no-op"
targos May 6, 2025
f54a7a4
Revert "deps: patch V8 to support compilation with MSVC"
targos May 6, 2025
329e008
src: refactor WriteUCS2 and remove flags argument
tniessen May 8, 2025
868e72e
lib: fix sourcemaps with ts module mocking
marco-ippolito May 8, 2025
b94f63b
module: handle instantiated async module jobs in require(esm)
joyeecheung May 8, 2025
bb28e2b
src: remove overzealous tcsetattr error check
bnoordhuis May 8, 2025
7715722
http: remove unused functions and add todos
anonrig May 9, 2025
9ca4b46
src: use String::WriteV2() in TwoByteValue
tniessen May 9, 2025
f7041b9
Revert "test_runner: change ts default glob"
theoludwig May 9, 2025
ebb82aa
test: deflake test-http2-client-socket-destroy
lpinca May 9, 2025
abeb5c4
src: fix module buffer allocation
Whitecx May 9, 2025
6568373
test: fix executable flags
LiviaMedeiros May 10, 2025
6ebcce7
fs: ensure `dir.read()` does not throw synchronously
aduh95 May 8, 2025
db57f0a
deps: patch V8 to 13.6.233.10
targos May 8, 2025
5a5f6bb
deps: V8: cherry-pick 044b9b6f589d
rmahdav May 1, 2025
63f5d69
deps: V8: cherry-pick 4f38995c8295
syg May 5, 2025
30897d9
deps: V8: backport 1d3362c55396
syg May 6, 2025
a135c0a
src: remove unneeded explicit V8 flags
targos May 8, 2025
97f8037
test: add `Float16Array` to `common.getArrayBufferViews()`
LiviaMedeiros May 10, 2025
655326b
fs: glob is stable, so should not emit experimental warnings
theoludwig May 10, 2025
2cb86a3
http2: add diagnostics channel 'http2.client.stream.created'
RaisinTen May 11, 2025
c26863a
doc: fix typo of file `http.md`, `outgoingMessage.setTimeout` section
samuel871211 May 11, 2025
fcead7c
fs: add to `Dir` support for explicit resource management
aduh95 May 11, 2025
1774612
sqlite: set `name` and `length` on `sqlite.backup()`
LiviaMedeiros May 11, 2025
130c135
fs: add support for `URL` for `fs.glob`'s `cwd` option
aduh95 May 11, 2025
b8d4715
tools: support environment variables via comments
pmarchini May 11, 2025
2d5de7e
tools: add read permission to workflows that read contents
aduh95 May 11, 2025
d8e88f2
typings: add missing typings for `TypedArray`
jazelly May 12, 2025
a1b078b
buffer: give names to `Buffer.prototype.*Write()` functions
LiviaMedeiros May 12, 2025
a896eff
crypto: handle missing OPENSSL_TLS_SECURITY_LEVEL
codebytere May 12, 2025
74a807e
http,https: give names to anonymous or misnamed functions
LiviaMedeiros May 12, 2025
b66f1b0
inspector: support for worker inspection in chrome devtools
islandryu May 12, 2025
290a5ab
doc: clarify napi_get_value_string_* for bufsize 0
tniessen May 12, 2025
3b8d4e3
src: add a couple fast apis in node_os
jasnell May 7, 2025
a3af644
test: allow `tmpDir.path` to be modified
avivkeller May 12, 2025
4db5d0b
src: remove unused `shouldRetryAsESM` internal binding
dario-piotrowicz May 12, 2025
cb24fc7
src: remove unused `checkMessagePort` internal binding
dario-piotrowicz May 12, 2025
e0355b7
src: add a variant of ToV8Value() for primitive arrays
Aditi-1400 Mar 18, 2025
327095a
build: fix uvwasi pkgname
aduh95 May 12, 2025
fc30cdd
doc: update stability status for diagnostics_channel to experimental
idango10 May 13, 2025
b7d1bfa
doc: add puskin to collaborators
puskin May 13, 2025
a1b937b
doc: update commit-queue documentation
dario-piotrowicz May 13, 2025
3ed159a
watch: fix watch args not being properly filtered
dario-piotrowicz May 13, 2025
40dc092
test: remove unnecessary `console.log` from test-repl-null-thrown
dario-piotrowicz May 13, 2025
685d137
test: reduce iteration count in test-child-process-stdout-flush-exit
aduh95 May 13, 2025
a92a407
src: remove unused `internalVerifyIntegrity` internal binding
dario-piotrowicz May 13, 2025
f0cf1a0
doc: make Stability labels not sticky in Stability index
LiviaMedeiros May 14, 2025
24a9aef
http2: add diagnostics channel 'http2.client.stream.start'
RaisinTen May 14, 2025
3b9b010
doc: remove comma delimiter mention on permissions doc
RafaelGSS May 14, 2025
f04f09d
doc: mark the callback argument of crypto.generatePrime as mandatory
mureinik May 14, 2025
2bb433d
doc: fix CryptoKey.algorithm type and other interfaces in webcrypto.md
panva May 14, 2025
c35cc1b
doc: document default test-reporter change
nicojs May 14, 2025
2676ca0
doc: add latest security release steward
RafaelGSS May 15, 2025
6301b00
tools: ignore `deps/` and `benchmark/` for CodeQL
RafaelGSS May 15, 2025
570cb6f
meta: ignore mailmap changes in linux ci
JonasBa May 16, 2025
9d35b4c
doc: add JonasBa to collaborators
JonasBa May 16, 2025
587a88b
2025-05-21, Version 24.1.0 (Current)
nodejs-github-bot May 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
url: improve performance of the format function
PR-URL: #57099
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Chemi Atlow <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Reviewed-By: Rafael Gonzaga <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
  • Loading branch information
puskin authored and targos committed May 16, 2025
commit 4c6f73c5d55dc74afb5525b14f8077eb83a952a7
71 changes: 37 additions & 34 deletions lib/url.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const {
ObjectAssign,
ObjectKeys,
StringPrototypeCharCodeAt,
StringPrototypeIndexOf,
StringPrototypeReplaceAll,
StringPrototypeSlice,
decodeURIComponent,
} = primordials;

Expand Down Expand Up @@ -637,6 +640,10 @@ Url.prototype.format = function format() {
}

let protocol = this.protocol || '';
if (protocol && StringPrototypeCharCodeAt(protocol, protocol.length - 1) !== 58 /* : */) {
protocol += ':';
}

let pathname = this.pathname || '';
let hash = this.hash || '';
let host = '';
Expand All @@ -646,7 +653,7 @@ Url.prototype.format = function format() {
host = auth + this.host;
} else if (this.hostname) {
host = auth + (
this.hostname.includes(':') && !isIpv6Hostname(this.hostname) ?
StringPrototypeIndexOf(this.hostname, ':') !== -1 && !isIpv6Hostname(this.hostname) ?
'[' + this.hostname + ']' :
this.hostname
);
Expand All @@ -658,59 +665,55 @@ Url.prototype.format = function format() {
if (this.query !== null && typeof this.query === 'object') {
query = querystring.stringify(this.query);
}

let search = this.search || (query && ('?' + query)) || '';

if (protocol && protocol.charCodeAt(protocol.length - 1) !== 58/* : */)
protocol += ':';

let newPathname = '';
let lastPos = 0;
for (let i = 0; i < pathname.length; ++i) {
switch (pathname.charCodeAt(i)) {
case CHAR_HASH:
if (i - lastPos > 0)
newPathname += pathname.slice(lastPos, i);
newPathname += '%23';
lastPos = i + 1;
break;
case CHAR_QUESTION_MARK:
if (i - lastPos > 0)
newPathname += pathname.slice(lastPos, i);
newPathname += '%3F';
if (StringPrototypeIndexOf(pathname, '#') !== -1 || StringPrototypeIndexOf(pathname, '?') !== -1) {
let newPathname = '';
let lastPos = 0;
const len = pathname.length;
for (let i = 0; i < len; i++) {
const code = StringPrototypeCharCodeAt(pathname, i);
if (code === CHAR_HASH || code === CHAR_QUESTION_MARK) {
if (i > lastPos) {
newPathname += StringPrototypeSlice(pathname, lastPos, i);
}
newPathname += (code === CHAR_HASH ? '%23' : '%3F');
lastPos = i + 1;
break;
}
}
}
if (lastPos > 0) {
if (lastPos !== pathname.length)
pathname = newPathname + pathname.slice(lastPos);
else
pathname = newPathname;
if (lastPos < len) {
newPathname += StringPrototypeSlice(pathname, lastPos);
}
pathname = newPathname;
}

// Only the slashedProtocols get the //. Not mailto:, xmpp:, etc.
// unless they had them to begin with.
if (this.slashes || slashedProtocol.has(protocol)) {
if (this.slashes || host) {
if (pathname && pathname.charCodeAt(0) !== CHAR_FORWARD_SLASH)
if (pathname && StringPrototypeCharCodeAt(pathname, 0) !== CHAR_FORWARD_SLASH)
pathname = '/' + pathname;
host = '//' + host;
} else if (protocol.length >= 4 &&
protocol.charCodeAt(0) === 102/* f */ &&
protocol.charCodeAt(1) === 105/* i */ &&
protocol.charCodeAt(2) === 108/* l */ &&
protocol.charCodeAt(3) === 101/* e */) {
StringPrototypeCharCodeAt(protocol, 0) === 102/* f */ &&
StringPrototypeCharCodeAt(protocol, 1) === 105/* i */ &&
StringPrototypeCharCodeAt(protocol, 2) === 108/* l */ &&
StringPrototypeCharCodeAt(protocol, 3) === 101/* e */) {
host = '//';
}
}

search = search.replaceAll('#', '%23');
// Escape '#' in search.
if (StringPrototypeIndexOf(search, '#') !== -1) {
search = StringPrototypeReplaceAll(search, '#', '%23');
}

if (hash && hash.charCodeAt(0) !== CHAR_HASH)
if (hash && StringPrototypeCharCodeAt(hash, 0) !== CHAR_HASH) {
hash = '#' + hash;
if (search && search.charCodeAt(0) !== CHAR_QUESTION_MARK)
}
if (search && StringPrototypeCharCodeAt(search, 0) !== CHAR_QUESTION_MARK) {
search = '?' + search;
}

return protocol + host + pathname + search + hash;
};
Expand Down