GeezerVison is showing github.com — util: fix inspecting URL subclass prototypes · nodejs/node@3f5f257
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: lib/internal/util/inspect.js +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -205,7 +205,7 @@ function pathToFileUrlHref(filepath) { |
205 | 205 |
|
206 | 206 | function isURL(value) { |
207 | 207 | internalUrl ??= require('internal/url'); |
208 | | - return typeof value.href === 'string' && value instanceof internalUrl.URL; |
| 208 | + return internalUrl.isURLInstance(value) && typeof value.href === 'string'; |
209 | 209 | } |
210 | 210 |
|
211 | 211 | const builtInObjects = new SafeSet( |
|
Collapse file
Copy file name to clipboard +35Lines changed: 35 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
| 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 | +); |