Fix #31133: url.domainToASCII returns empty string for invalid domains #31219
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR fixes the behavior of
url.domainToASCIIto match Node.js by returning an empty string when an invalid domain is passed, instead of throwing an error.Changes
op_node_idna_domain_to_asciiinext/node/ops/idna.rsto return an empty string on error instead of propagating the errorext/node/polyfills/internal/idna.tsto clarify this behaviortests/specs/node/url_domain_to_ascii/to verify the fixTest Plan
Manual Testing
Tested with the example from the issue:
Also tested with various valid and invalid domains to ensure compatibility:
example.com→example.commünchen.de→xn--mnchen-3ya.dexn--iñvalid.com→ `` (empty string)xn--→ `` (empty string)Automated Tests
Added spec test that verifies the behavior matches Node.js for both valid and invalid domains.
Closes
Fixes #31133
This PR was autogenerated and may require review and adjustments.
🤖 Generated with Claude Code