mirror of
https://github.com/nodejs/node.git
synced 2025-05-10 19:17:56 +00:00

This commit contains three separate changes: - Always return a string from ToUnicode no matter if an error occurred. - Disable CheckHyphens boolean flag. This flag will soon be enabled in the URL Standard, but is implemented manually by selectively ignoring certain errors. - Enable CheckBidi boolean flag per URL Standard update. This allows domain names with hyphens at 3 and 4th position, as well as those with leading and trailing hyphens. They are technically invalid, but seen in the wild. Tests are updated and simplified accordingly. PR-URL: https://github.com/nodejs/node/pull/12966 Fixes: https://github.com/nodejs/node/issues/12965 Refs: https://github.com/whatwg/url/pull/309 Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
43 lines
1.4 KiB
JavaScript
43 lines
1.4 KiB
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
|
|
if (!common.hasIntl) {
|
|
common.skip('missing Intl');
|
|
return;
|
|
}
|
|
|
|
const assert = require('assert');
|
|
const { domainToASCII, domainToUnicode } = require('url');
|
|
|
|
// Tests below are not from WPT.
|
|
const tests = require('../fixtures/url-idna.js');
|
|
|
|
{
|
|
const expectedError = common.expectsError(
|
|
{ code: 'ERR_MISSING_ARGS', type: TypeError });
|
|
assert.throws(() => domainToASCII(), expectedError);
|
|
assert.throws(() => domainToUnicode(), expectedError);
|
|
assert.strictEqual(domainToASCII(undefined), 'undefined');
|
|
assert.strictEqual(domainToUnicode(undefined), 'undefined');
|
|
}
|
|
|
|
{
|
|
for (const [i, { ascii, unicode }] of tests.valid.entries()) {
|
|
assert.strictEqual(ascii, domainToASCII(unicode),
|
|
`domainToASCII(${i + 1})`);
|
|
assert.strictEqual(unicode, domainToUnicode(ascii),
|
|
`domainToUnicode(${i + 1})`);
|
|
assert.strictEqual(ascii, domainToASCII(domainToUnicode(ascii)),
|
|
`domainToASCII(domainToUnicode(${i + 1}))`);
|
|
assert.strictEqual(unicode, domainToUnicode(domainToASCII(unicode)),
|
|
`domainToUnicode(domainToASCII(${i + 1}))`);
|
|
}
|
|
}
|
|
|
|
{
|
|
for (const [i, url] of tests.invalid.entries()) {
|
|
assert.strictEqual(domainToASCII(url), '', `Invalid case ${i + 1}`);
|
|
assert.strictEqual(domainToUnicode(url), '', `Invalid case ${i + 1}`);
|
|
}
|
|
}
|