Commit 531d28fc360 for nodejs
commit 531d28fc360bd40b427561b1f85fd18743138626
Author: Donghoon Kang <d159123@naver.com>
Date: Tue Oct 20 13:54:54 2026 +0900
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>
PR-URL: https://github.com/nodejs/node/pull/66822
Fixes: https://github.com/nodejs/node/issues/66821
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Matthew Aitken <maitken033380023@gmail.com>
diff --git a/lib/internal/util/inspect.js b/lib/internal/util/inspect.js
index 622dab4eae8..3d36c5793be 100644
--- a/lib/internal/util/inspect.js
+++ b/lib/internal/util/inspect.js
@@ -205,7 +205,7 @@ function pathToFileUrlHref(filepath) {
function isURL(value) {
internalUrl ??= require('internal/url');
- return typeof value.href === 'string' && value instanceof internalUrl.URL;
+ return internalUrl.isURLInstance(value) && typeof value.href === 'string';
}
const builtInObjects = new SafeSet(
diff --git a/test/parallel/test-util-inspect-url.js b/test/parallel/test-util-inspect-url.js
new file mode 100644
index 00000000000..3635e9ab9f7
--- /dev/null
+++ b/test/parallel/test-util-inspect-url.js
@@ -0,0 +1,35 @@
+'use strict';
+
+require('../common');
+const assert = require('assert');
+const { format, inspect } = require('util');
+
+class TestURL extends URL {}
+
+assert.strictEqual(inspect(TestURL.prototype), 'URL {}');
+assert.strictEqual(
+ inspect(TestURL.prototype, { customInspect: false }),
+ 'URL {}',
+);
+
+// Inspecting hidden properties must not throw when reaching the prototype.
+inspect(TestURL, { showHidden: true });
+inspect({ TestURL }, { showHidden: true });
+format('%o', { TestURL });
+
+const url = new TestURL('https://example.org/');
+assert.strictEqual(
+ inspect(url, { customInspect: false }),
+ 'https://example.org/',
+);
+
+class NonStringURL extends URL {
+ get href() {
+ return undefined;
+ }
+}
+
+assert.strictEqual(
+ inspect(new NonStringURL('https://example.org/'), { customInspect: false }),
+ 'NonStringURL [URL] {}',
+);