Skip to content

Commit 83ea3a3

Browse files
committed
util: fix inspecting URL subclass prototypes
Check the URL private field brand before accessing href to avoid throwing when inspecting URL subclass prototypes. Assisted-by:Codex:6.1SolHigh Signed-off-by: HoonDongKang <d159123@naver.com>
1 parent f88a1d2 commit 83ea3a3

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

‎lib/internal/util/inspect.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ function pathToFileUrlHref(filepath) {
205205

206206
function isURL(value) {
207207
internalUrl ??= require('internal/url');
208-
return typeof value.href === 'string' && value instanceof internalUrl.URL;
208+
return internalUrl.isURLInstance(value) && typeof value.href === 'string';
209209
}
210210

211211
const builtInObjects = new SafeSet(
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
'use strict';
2+
3+
require('../common');
4+
const assert = require('assert');
5+
const { format, inspect } = require('util');
6+
7+
class TestURL extends URL {}
8+
9+
assert.strictEqual(inspect(TestURL.prototype), 'URL {}');
10+
assert.strictEqual(
11+
inspect(TestURL.prototype, { customInspect: false }),
12+
'URL {}',
13+
);
14+
15+
// Inspecting hidden properties must not throw when reaching the prototype.
16+
inspect(TestURL, { showHidden: true });
17+
inspect({ TestURL }, { showHidden: true });
18+
format('%o', { TestURL });
19+
20+
const url = new TestURL('https://example.org/');
21+
assert.strictEqual(
22+
inspect(url, { customInspect: false }),
23+
'https://example.org/',
24+
);
25+
26+
class NonStringURL extends URL {
27+
get href() {
28+
return undefined;
29+
}
30+
}
31+
32+
assert.strictEqual(
33+
inspect(new NonStringURL('https://example.org/'), { customInspect: false }),
34+
'NonStringURL [URL] {}',
35+
);

0 commit comments

Comments
 (0)