Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
var common = require('../common');
var punycode = require('punycode');
var assert = require('assert');
assert.equal(punycode.encode('ü'), 'tda');
assert.equal(punycode.encode('Goethe'), 'Goethe-');
assert.equal(punycode.encode('Bücher'), 'Bcher-kva');
assert.equal(punycode.encode(
'Willst du die Blüthe des frühen, die Früchte des späteren Jahres'),
'Willst du die Blthe des frhen, die Frchte des spteren Jahres-x9e96lkal');
assert.equal(punycode.encode('日本語'), 'wgv71a119e');
assert.equal(punycode.decode('tda'), 'ü');
assert.equal(punycode.decode('Goethe-'), 'Goethe');
assert.equal(punycode.decode('Bcher-kva'), 'Bücher');
assert.equal(punycode.decode(
'Willst du die Blthe des frhen, die Frchte des spteren Jahres-x9e96lkal'),
'Willst du die Blüthe des frühen, die Früchte des späteren Jahres');
assert.equal(punycode.decode('wgv71a119e'), '日本語');
// http://tools.ietf.org/html/rfc3492#section-7.1
var tests = {
// (A) Arabic (Egyptian)
'egbpdaj6bu4bxfgehfvwxn':
'\u0644\u064A\u0647\u0645\u0627\u0628\u062A\u0643\u0644\u0645\u0648' +
'\u0634\u0639\u0631\u0628\u064A\u061F',
// (B) Chinese (simplified)
'ihqwcrb4cv8a8dqg056pqjye':
'\u4ED6\u4EEC\u4E3A\u4EC0\u4E48\u4E0D\u8BF4\u4E2D\u6587',
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
var common = require('../common');
var punycode = require('punycode');
var assert = require('assert');
assert.equal(punycode.encode('ü'), 'tda');
assert.equal(punycode.encode('Goethe'), 'Goethe-');
assert.equal(punycode.encode('Bücher'), 'Bcher-kva');
assert.equal(punycode.encode(
'Willst du die Blüthe des frühen, die Früchte des späteren Jahres'),
'Willst du die Blthe des frhen, die Frchte des spteren Jahres-x9e96lkal');
assert.equal(punycode.encode('日本語'), 'wgv71a119e');
assert.equal(punycode.decode('tda'), 'ü');
assert.equal(punycode.decode('Goethe-'), 'Goethe');
assert.equal(punycode.decode('Bcher-kva'), 'Bücher');
assert.equal(punycode.decode(
'Willst du die Blthe des frhen, die Frchte des spteren Jahres-x9e96lkal'),
'Willst du die Blüthe des frühen, die Früchte des späteren Jahres');
assert.equal(punycode.decode('wgv71a119e'), '日本語');
// http://tools.ietf.org/html/rfc3492#section-7.1
var tests = {
// (A) Arabic (Egyptian)
'egbpdaj6bu4bxfgehfvwxn':
'\u0644\u064A\u0647\u0645\u0627\u0628\u062A\u0643\u0644\u0645\u0648' +
'\u0634\u0639\u0631\u0628\u064A\u061F',
// (B) Chinese (simplified)
'ihqwcrb4cv8a8dqg056pqjye':
assert.equal(punycode.encode('ü'), 'tda');
assert.equal(punycode.encode('Goethe'), 'Goethe-');
assert.equal(punycode.encode('Bücher'), 'Bcher-kva');
assert.equal(punycode.encode(
'Willst du die Blüthe des frühen, die Früchte des späteren Jahres'),
'Willst du die Blthe des frhen, die Frchte des spteren Jahres-x9e96lkal');
assert.equal(punycode.encode('日本語'), 'wgv71a119e');
assert.equal(punycode.decode('tda'), 'ü');
assert.equal(punycode.decode('Goethe-'), 'Goethe');
assert.equal(punycode.decode('Bcher-kva'), 'Bücher');
assert.equal(punycode.decode(
'Willst du die Blthe des frhen, die Frchte des spteren Jahres-x9e96lkal'),
'Willst du die Blüthe des frühen, die Früchte des späteren Jahres');
assert.equal(punycode.decode('wgv71a119e'), '日本語');
// http://tools.ietf.org/html/rfc3492#section-7.1
var tests = {
// (A) Arabic (Egyptian)
'egbpdaj6bu4bxfgehfvwxn':
'\u0644\u064A\u0647\u0645\u0627\u0628\u062A\u0643\u0644\u0645\u0648' +
'\u0634\u0639\u0631\u0628\u064A\u061F',
// (B) Chinese (simplified)
'ihqwcrb4cv8a8dqg056pqjye':
'\u4ED6\u4EEC\u4E3A\u4EC0\u4E48\u4E0D\u8BF4\u4E2D\u6587',
// (C) Chinese (traditional)
'ihqwctvzc91f659drss3x8bo0yb':
'\u4ED6\u5011\u7232\u4EC0\u9EBD\u4E0D\u8AAA\u4E2D\u6587',
let { string, error } = mapChars(domainName, options);
// 2. Normalize.
string = string.normalize("NFC");
// 3. Break.
const labels = string.split(".");
const isBidi = isBidiDomain(labels);
// 4. Convert/Validate.
for (const [i, origLabel] of labels.entries()) {
let label = origLabel;
let curProcessing = processingOption;
if (label.startsWith("xn--")) {
try {
label = punycode.decode(label.substring(4));
labels[i] = label;
} catch (err) {
error = true;
continue;
}
curProcessing = "nontransitional";
}
// No need to validate if we already know there is an error.
if (error) {
continue;
}
const validation = validateLabel(label, Object.assign({}, options, {
processingOption: curProcessing,
checkBidi: options.checkBidi && isBidi
}));
let { string, error } = mapChars(domainName, options);
// 2. Normalize.
string = string.normalize("NFC");
// 3. Break.
const labels = string.split(".");
const isBidi = isBidiDomain(labels);
// 4. Convert/Validate.
for (const [i, origLabel] of labels.entries()) {
let label = origLabel;
let curProcessing = processingOption;
if (label.startsWith("xn--")) {
try {
label = punycode.decode(label.substring(4));
labels[i] = label;
} catch (err) {
error = true;
continue;
}
curProcessing = "nontransitional";
}
// No need to validate if we already know there is an error.
if (error) {
continue;
}
const validation = validateLabel(label, Object.assign({}, options, {
processingOption: curProcessing,
checkBidi: options.checkBidi && isBidi
}));
'-> $1.00 <--':
'\u002D\u003E\u0020\u0024\u0031\u002E\u0030\u0030\u0020\u003C\u002D'
};
var errors = 0;
for (var encoded in tests) {
var decoded = tests[encoded];
try {
assert.equal(punycode.encode(decoded), encoded);
} catch (e) {
console.error('FAIL: expected %j, got %j', e.expected, e.actual);
errors++;
}
try {
assert.equal(punycode.decode(encoded), decoded);
} catch (e) {
console.error('FAIL: expected %j, got %j', e.expected, e.actual);
errors++;
}
}
assert.equal(errors, 0);
const domain = labels.map(label => {
if (label.startsWith("xn--")) {
try {
return punycode.decode(label.substring(4));
} catch (err) {
return "";
}
}
return label;
}).join(".");
return regexes.bidiDomain.test(domain);
const domain = labels.map(label => {
if (label.startsWith("xn--")) {
try {
return punycode.decode(label.substring(4));
} catch (err) {
return "";
}
}
return label;
}).join(".");
return regexes.bidiDomain.test(domain);
runToUnicode: function(input, args) {
const idn = args[0];
if (idn) {
return punycode.toUnicode(input);
} else {
return punycode.decode(input);
}
},
.map(tld => punycode.decode(tld.substr(4)))
);