Skip to content

Conversation

@denobot
Copy link
Collaborator

@denobot denobot commented Nov 6, 2025

Summary

This PR fixes the behavior of url.domainToASCII to match Node.js by returning an empty string when an invalid domain is passed, instead of throwing an error.

Changes

  • Modified op_node_idna_domain_to_ascii in ext/node/ops/idna.rs to return an empty string on error instead of propagating the error
  • Updated documentation in ext/node/polyfills/internal/idna.ts to clarify this behavior
  • Added spec test in tests/specs/node/url_domain_to_ascii/ to verify the fix

Test Plan

Manual Testing

Tested with the example from the issue:

import url from 'node:url';
console.log(url.domainToASCII('xn--iñvalid.com')); // Returns empty string instead of throwing

Also tested with various valid and invalid domains to ensure compatibility:

  • Valid domains: example.comexample.com
  • Valid unicode: münchen.dexn--mnchen-3ya.de
  • Invalid punycode: xn--iñvalid.com → `` (empty string)
  • Invalid domain: 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

This fixes the behavior of url.domainToASCII to match Node.js by returning
an empty string when an invalid domain is passed instead of throwing an error.

Previously, passing an invalid punycode domain like "xn--iñvalid.com" would
throw an error. Now it returns an empty string as per Node.js behavior.

Changes:
- Modified op_node_idna_domain_to_ascii in ext/node/ops/idna.rs to return
  an empty string on error instead of propagating the error
- Updated documentation in ext/node/polyfills/internal/idna.ts
- Added spec test to verify the fix

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

url.domainToASCII cannot handle invalid domains

2 participants