Skip to content

util: fix inspecting URL subclass prototypes - #66822

Open
HoonDongKang wants to merge 1 commit into
nodejs:mainfrom
HoonDongKang:util/fix-inspecting-url-subclass
Open

HoonDongKang wants to merge 1 commit into
nodejs:mainfrom
HoonDongKang:util/fix-inspecting-url-subclass

Conversation

@HoonDongKang

@HoonDongKang HoonDongKang commented Oct 18, 2026 •

Copy link
Copy Markdown
Member

Inspecting a URL subclass prototype throws a TypeError:

const { inspect } = require('node:util');

class TestURL extends URL {}

inspect(TestURL.prototype);
// TypeError: Receiver must be an instance of class URL

isURL() accessed value.href before checking instanceof URLand it invokes the getter on this prototype.

Use isURLInstance() to check for URL internal state before reading href:

- return typeof value.href === 'string' && value instanceof internalUrl.URL;
+ return internalUrl.isURLInstance(value) && typeof value.href === 'string';

The check returns false for subclass prototypes without invoking the getter, allowing inspection to continue through the generic object formatting path.

Add regression tests for subclass prototypes, class references inspected with showHidden: true, and %o formatting. Also cover normal subclass instances and an overridden href getter returning undefined with customInspect: false.

Fixes: #66821
Assisted-by: Codex:6.1-sol-high

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>
@nodejs-github-bot nodejs-github-bot added needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module. labels Oct 18, 2026
@codecov

codecov Bot commented Oct 18, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.49%. Comparing base (f88a1d2) to head (83ea3a3).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #66822      +/-   ##
==========================================
- Coverage   90.49%   90.49%   -0.01%     
==========================================
  Files         797      797              
  Lines      277780   277780              
  Branches    53360    53359       -1     
==========================================
- Hits       251388   251367      -21     
- Misses      16791    16804      +13     
- Partials     9601     9609       +8     
Files with missing lines Coverage Δ
lib/internal/util/inspect.js 97.04% <100.00%> (ø)

... and 28 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-ci PRs that need a full CI run. util Issues and PRs related to the built-in util module.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

util.inspect() throws on prototypes of URL subclasses

2 participants