Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
{ code: 'ERR_MISSING_ARGS', type: TypeError }, 2);
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.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, test] of wptToASCIITests.entries()) {
if (typeof test === 'string')
continue; // skip comments
const { comment, input, output } = test;
let caseComment = `Case ${i + 1}`;
if (comment)
caseComment += ` (${comment})`;
if (output === null) {
assert.strictEqual(domainToASCII(input), '', caseComment);
assert.strictEqual(domainToUnicode(input), '', caseComment);
} else {
}
{
for (const [i, test] of wptToASCIITests.entries()) {
if (typeof test === 'string')
continue; // skip comments
const { comment, input, output } = test;
let caseComment = `Case ${i + 1}`;
if (comment)
caseComment += ` (${comment})`;
if (output === null) {
assert.strictEqual(domainToASCII(input), '', caseComment);
assert.strictEqual(domainToUnicode(input), '', caseComment);
} else {
assert.strictEqual(domainToASCII(input), output, caseComment);
const roundtripped = domainToASCII(domainToUnicode(input));
assert.strictEqual(roundtripped, output, caseComment);
}
}
}
{
const expectedError = common.expectsError(
{ code: 'ERR_MISSING_ARGS', type: TypeError }, 2);
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.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, test] of wptToASCIITests.entries()) {
if (typeof test === 'string')
continue; // skip comments
const { comment, input, output } = test;
let caseComment = `Case ${i + 1}`;
if (comment)
caseComment += ` (${comment})`;
if (output === null) {
assert.strictEqual(domainToASCII(input), '', caseComment);
`domainToASCII(domainToUnicode(${i + 1}))`);
assert.strictEqual(unicode, domainToUnicode(domainToASCII(unicode)),
`domainToUnicode(domainToASCII(${i + 1}))`);
}
}
{
for (const [i, test] of wptToASCIITests.entries()) {
if (typeof test === 'string')
continue; // skip comments
const { comment, input, output } = test;
let caseComment = `Case ${i + 1}`;
if (comment)
caseComment += ` (${comment})`;
if (output === null) {
assert.strictEqual(domainToASCII(input), '', caseComment);
assert.strictEqual(domainToUnicode(input), '', caseComment);
} else {
assert.strictEqual(domainToASCII(input), output, caseComment);
const roundtripped = domainToASCII(domainToUnicode(input));
assert.strictEqual(roundtripped, output, caseComment);
}
}
}
const wptToASCIITests = require(
fixtures.path('wpt', 'url', 'resources', 'toascii.json')
);
{
const expectedError = common.expectsError(
{ code: 'ERR_MISSING_ARGS', type: TypeError }, 2);
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.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, test] of wptToASCIITests.entries()) {
if (typeof test === 'string')
continue; // skip comments
const { comment, input, output } = test;
let caseComment = `Case ${i + 1}`;
host: "google.com",
pathname: 'search',
query: { q: "you're a lizard, gary" }
});
const myURL = new url.URL('https://a:b@你好你好?abc#foo');
url.format(myURL, { fragment: false, unicode: true, auth: false });
}
{
var helloUrl = url.parse('http://example.com/?hello=world', true)
assert.equal(helloUrl.query.hello, 'world');
}
{
const ascii: string = url.domainToASCII('español.com');
const unicode: string = url.domainToUnicode('xn--espaol-zwa.com');
}
{
let myURL = new url.URL('https://theuser:thepwd@example.org:81/foo/path?query=string#bar');
assert.equal(myURL.hash, '#bar');
assert.equal(myURL.host, 'example.org:81');
assert.equal(myURL.hostname, 'example.org');
assert.equal(myURL.href, 'https://theuser:thepwd@example.org:81/foo/path?query=string#bar');
assert.equal(myURL.origin, 'https://example.org:81');
assert.equal(myURL.password, 'thepwd');
assert.equal(myURL.username, 'theuser');
assert.equal(myURL.pathname, '/foo/path');
assert.equal(myURL.port, "81");
assert.equal(myURL.protocol, "https:");
assert.equal(myURL.search, "?query=string");
let queryStr: string = strUrl.query!;
strUrl = url.parse('http://example.com/?hello=world', false);
queryStr = strUrl.query!;
function getBoolean(): boolean { return false; }
const urlUrl = url.parse('http://example.com/?hello=world', getBoolean());
if (typeof(urlUrl.query) === 'string') {
queryStr = urlUrl.query;
} else if (urlUrl.query) {
helloQuery = urlUrl.query['hello'];
}
}
{
const ascii: string = url.domainToASCII('español.com');
const unicode: string = url.domainToUnicode('xn--espaol-zwa.com');
}
{
let myURL = new url.URL('https://theuser:thepwd@example.org:81/foo/path?query=string#bar');
assert.equal(myURL.hash, '#bar');
assert.equal(myURL.host, 'example.org:81');
assert.equal(myURL.hostname, 'example.org');
assert.equal(myURL.href, 'https://theuser:thepwd@example.org:81/foo/path?query=string#bar');
assert.equal(myURL.origin, 'https://example.org:81');
assert.equal(myURL.password, 'thepwd');
assert.equal(myURL.username, 'theuser');
assert.equal(myURL.pathname, '/foo/path');
assert.equal(myURL.port, "81");
assert.equal(myURL.protocol, "https:");
assert.equal(myURL.search, "?query=string");
const assert = require('assert');
const { domainToASCII, domainToUnicode } = require('url');
const tests = require('../fixtures/url-idna');
const fixtures = require('../common/fixtures');
const wptToASCIITests = require(
fixtures.path('wpt', 'url', 'resources', 'toascii.json')
);
{
const expectedError = common.expectsError(
{ code: 'ERR_MISSING_ARGS', type: TypeError }, 2);
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.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}))`);
}
}
exports.normalize = (email) => {
const localEnd = email.indexOf('@')
if (localEnd === -1) return ''
const local = email.slice(0, localEnd).toLowerCase()
if (local === '') return ''
const host = url.domainToASCII(email.slice(localEnd + 1))
if (host === '' || host[0] === '[' || net.isIPv4(host)) return ''
return `${local}@${host}`
}