mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 18:38:55 +00:00
## Summary
- Fixes `url.domainToASCII` and `url.domainToUnicode` to return empty
string instead of throwing `TypeError` when given invalid domains
- Per Node.js docs: "if `domain` is an invalid domain, the empty string
is returned"
## Test plan
- [x] Run `bun bd test test/regression/issue/24191.test.ts` - all 2
tests pass
- [x] Verify tests fail with system Bun (`USE_SYSTEM_BUN=1`) to confirm
fix validity
- [x] Manual verification: `url.domainToASCII('xn--iñvalid.com')`
returns `""`
## Example
Before (bug):
```
$ bun -e "import url from 'node:url'; console.log(url.domainToASCII('xn--iñvalid.com'))"
TypeError: domainToASCII failed
```
After (fixed):
```
$ bun -e "import url from 'node:url'; console.log(url.domainToASCII('xn--iñvalid.com'))"
(empty string output)
```
Closes #24191
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude <noreply@anthropic.com>
23 lines
984 B
TypeScript
23 lines
984 B
TypeScript
import { expect, test } from "bun:test";
|
|
import url from "node:url";
|
|
|
|
// Regression test for issue #24191
|
|
// url.domainToASCII should return empty string for invalid domains, not throw
|
|
test("url.domainToASCII returns empty string for invalid domains", () => {
|
|
// Invalid punycode with non-ASCII characters should return empty string, not throw
|
|
expect(url.domainToASCII("xn--iñvalid.com")).toBe("");
|
|
|
|
// Valid domains should still work
|
|
expect(url.domainToASCII("example.com")).toBe("example.com");
|
|
expect(url.domainToASCII("münchen.de")).toBe("xn--mnchen-3ya.de");
|
|
});
|
|
|
|
test("url.domainToUnicode returns empty string for invalid domains", () => {
|
|
// Invalid punycode with non-ASCII characters should return empty string, not throw
|
|
expect(url.domainToUnicode("xn--iñvalid.com")).toBe("");
|
|
|
|
// Valid domains should still work
|
|
expect(url.domainToUnicode("example.com")).toBe("example.com");
|
|
expect(url.domainToUnicode("xn--mnchen-3ya.de")).toBe("münchen.de");
|
|
});
|