This commit is contained in:
Stephen Franceschelli 2019-07-30 13:41:05 -04:00
parent 596a6da241
commit c1a589c5b6
7078 changed files with 1882834 additions and 319 deletions

21
node_modules/tr46/LICENSE.md generated vendored Normal file
View file

@ -0,0 +1,21 @@
The MIT License (MIT)
Copyright (c) 2016 Sebastian Mayr
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

69
node_modules/tr46/README.md generated vendored Normal file
View file

@ -0,0 +1,69 @@
# tr46.js
> An implementation of the [Unicode TR46 specification](http://unicode.org/reports/tr46/).
## Installation
[Node.js](http://nodejs.org) `>= 6` is required. To install, type this at the command line:
```shell
npm install tr46
```
## API
### `toASCII(domainName[, options])`
Converts a string of Unicode symbols to a case-folded Punycode string of ASCII symbols.
Available options:
* [`checkBidi`](#checkBidi)
* [`checkHyphens`](#checkHyphens)
* [`checkJoiners`](#checkJoiners)
* [`processingOption`](#processingOption)
* [`useSTD3ASCIIRules`](#useSTD3ASCIIRules)
* [`verifyDNSLength`](#verifyDNSLength)
### `toUnicode(domainName[, options])`
Converts a case-folded Punycode string of ASCII symbols to a string of Unicode symbols.
Available options:
* [`checkBidi`](#checkBidi)
* [`checkHyphens`](#checkHyphens)
* [`checkJoiners`](#checkJoiners)
* [`useSTD3ASCIIRules`](#useSTD3ASCIIRules)
## Options
### `checkBidi`
Type: `Boolean`
Default value: `false`
When set to `true`, any bi-directional text within the input will be checked for validation.
### `checkHyphens`
Type: `Boolean`
Default value: `false`
When set to `true`, the positions of any hyphen characters within the input will be checked for validation.
### `checkJoiners`
Type: `Boolean`
Default value: `false`
When set to `true`, any word joiner characters within the input will be checked for validation.
### `processingOption`
Type: `String`
Default value: `"nontransitional"`
When set to `"transitional"`, symbols within the input will be validated according to the older IDNA2003 protocol. When set to `"nontransitional"`, the current IDNA2008 protocol will be used.
### `useSTD3ASCIIRules`
Type: `Boolean`
Default value: `false`
When set to `true`, input will be validated according to [STD3 Rules](http://unicode.org/reports/tr46/#STD3_Rules).
### `verifyDNSLength`
Type: `Boolean`
Default value: `false`
When set to `true`, the length of each DNS label within the input will be checked for validation.

287
node_modules/tr46/index.js generated vendored Normal file
View file

@ -0,0 +1,287 @@
"use strict";
const punycode = require("punycode");
const regexes = require("./lib/regexes.js");
const mappingTable = require("./lib/mappingTable.json");
function containsNonASCII(str) {
return /[^\x00-\x7F]/.test(str);
}
function findStatus(val, { useSTD3ASCIIRules }) {
let start = 0;
let end = mappingTable.length - 1;
while (start <= end) {
const mid = Math.floor((start + end) / 2);
const target = mappingTable[mid];
if (target[0][0] <= val && target[0][1] >= val) {
if (target[1].startsWith("disallowed_STD3_")) {
const newStatus = useSTD3ASCIIRules ? "disallowed" : target[1].slice(16);
return [newStatus, ...target.slice(2)];
}
return target.slice(1);
} else if (target[0][0] > val) {
end = mid - 1;
} else {
start = mid + 1;
}
}
return null;
}
function mapChars(domainName, { useSTD3ASCIIRules, processingOption }) {
let hasError = false;
let processed = "";
for (const ch of domainName) {
const [status, mapping] = findStatus(ch.codePointAt(0), { useSTD3ASCIIRules });
switch (status) {
case "disallowed":
hasError = true;
processed += ch;
break;
case "ignored":
break;
case "mapped":
processed += mapping;
break;
case "deviation":
if (processingOption === "transitional") {
processed += mapping;
} else {
processed += ch;
}
break;
case "valid":
processed += ch;
break;
}
}
return {
string: processed,
error: hasError
};
}
function validateLabel(label, { checkHyphens, checkBidi, checkJoiners, processingOption, useSTD3ASCIIRules }) {
if (label.normalize("NFC") !== label) {
return false;
}
const codePoints = Array.from(label);
if (checkHyphens) {
if ((codePoints[2] === "-" && codePoints[3] === "-") ||
(label.startsWith("-") || label.endsWith("-"))) {
return false;
}
}
if (label.includes(".") ||
(codePoints.length > 0 && regexes.combiningMarks.test(codePoints[0]))) {
return false;
}
for (const ch of codePoints) {
const [status] = findStatus(ch.codePointAt(0), { useSTD3ASCIIRules });
if ((processingOption === "transitional" && status !== "valid") ||
(processingOption === "nontransitional" &&
status !== "valid" && status !== "deviation")) {
return false;
}
}
// https://tools.ietf.org/html/rfc5892#appendix-A
if (checkJoiners) {
let last = 0;
for (const [i, ch] of codePoints.entries()) {
if (ch === "\u200C" || ch === "\u200D") {
if (i > 0) {
if (regexes.combiningClassVirama.test(codePoints[i - 1])) {
continue;
}
if (ch === "\u200C") {
// TODO: make this more efficient
const next = codePoints.indexOf("\u200C", i + 1);
const test = next < 0 ? codePoints.slice(last) : codePoints.slice(last, next);
if (regexes.validZWNJ.test(test.join(""))) {
last = i + 1;
continue;
}
}
}
return false;
}
}
}
// https://tools.ietf.org/html/rfc5893#section-2
if (checkBidi) {
let rtl;
// 1
if (regexes.bidiS1LTR.test(codePoints[0])) {
rtl = false;
} else if (regexes.bidiS1RTL.test(codePoints[0])) {
rtl = true;
} else {
return false;
}
if (rtl) {
// 2-4
if (!regexes.bidiS2.test(label) ||
!regexes.bidiS3.test(label) ||
(regexes.bidiS4EN.test(label) && regexes.bidiS4AN.test(label))) {
return false;
}
} else if (!regexes.bidiS5.test(label) ||
!regexes.bidiS6.test(label)) { // 5-6
return false;
}
}
return true;
}
function isBidiDomain(labels) {
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);
}
function processing(domainName, options) {
const { processingOption } = options;
// 1. Map.
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
}));
if (!validation) {
error = true;
}
}
return {
string: labels.join("."),
error
};
}
function toASCII(domainName, {
checkHyphens = false,
checkBidi = false,
checkJoiners = false,
useSTD3ASCIIRules = false,
processingOption = "nontransitional",
verifyDNSLength = false
} = {}) {
if (processingOption !== "transitional" && processingOption !== "nontransitional") {
throw new RangeError("processingOption must be either transitional or nontransitional");
}
const result = processing(domainName, {
processingOption,
checkHyphens,
checkBidi,
checkJoiners,
useSTD3ASCIIRules
});
let labels = result.string.split(".");
labels = labels.map(l => {
if (containsNonASCII(l)) {
try {
return "xn--" + punycode.encode(l);
} catch (e) {
result.error = true;
}
}
return l;
});
if (verifyDNSLength) {
const total = labels.join(".").length;
if (total > 253 || total === 0) {
result.error = true;
}
for (let i = 0; i < labels.length; ++i) {
if (labels[i].length > 63 || labels[i].length === 0) {
result.error = true;
break;
}
}
}
if (result.error) {
return null;
}
return labels.join(".");
}
function toUnicode(domainName, {
checkHyphens = false,
checkBidi = false,
checkJoiners = false,
useSTD3ASCIIRules = false
} = {}) {
const result = processing(domainName, {
processingOption: "nontransitional",
checkHyphens,
checkBidi,
checkJoiners,
useSTD3ASCIIRules
});
return {
domain: result.string,
error: result.error
};
}
module.exports = {
toASCII,
toUnicode
};

1
node_modules/tr46/lib/mappingTable.json generated vendored Normal file

File diff suppressed because one or more lines are too long

29
node_modules/tr46/lib/regexes.js generated vendored Normal file

File diff suppressed because one or more lines are too long

73
node_modules/tr46/package.json generated vendored Normal file
View file

@ -0,0 +1,73 @@
{
"_from": "tr46@^1.0.1",
"_id": "tr46@1.0.1",
"_inBundle": false,
"_integrity": "sha1-qLE/1r/SSJUZZ0zN5VujaTtwbQk=",
"_location": "/tr46",
"_phantomChildren": {},
"_requested": {
"type": "range",
"registry": true,
"raw": "tr46@^1.0.1",
"name": "tr46",
"escapedName": "tr46",
"rawSpec": "^1.0.1",
"saveSpec": null,
"fetchSpec": "^1.0.1"
},
"_requiredBy": [
"/data-urls/whatwg-url",
"/whatwg-url"
],
"_resolved": "https://registry.npmjs.org/tr46/-/tr46-1.0.1.tgz",
"_shasum": "a8b13fd6bfd2489519674ccde55ba3693b706d09",
"_spec": "tr46@^1.0.1",
"_where": "E:\\github\\setup-java\\node_modules\\data-urls\\node_modules\\whatwg-url",
"author": {
"name": "Sebastian Mayr",
"email": "npm@smayr.name"
},
"bugs": {
"url": "https://github.com/Sebmaster/tr46.js/issues"
},
"bundleDependencies": false,
"dependencies": {
"punycode": "^2.1.0"
},
"deprecated": false,
"description": "An implementation of the Unicode TR46 spec",
"devDependencies": {
"eslint": "^3.13.0",
"mocha": "^3.2.0",
"regenerate": "^1.3.2",
"request": "^2.79.0",
"unicode-10.0.0": "^0.7.4"
},
"files": [
"index.js",
"lib/mappingTable.json",
"lib/regexes.js"
],
"homepage": "https://github.com/Sebmaster/tr46.js#readme",
"keywords": [
"unicode",
"tr46",
"url",
"whatwg"
],
"license": "MIT",
"main": "index.js",
"name": "tr46",
"repository": {
"type": "git",
"url": "git+https://github.com/Sebmaster/tr46.js.git"
},
"scripts": {
"lint": "eslint .",
"prepublish": "node scripts/generateMappingTable.js && node scripts/generateRegexes.js",
"pretest": "node scripts/getLatestTests.js",
"test": "mocha"
},
"unicodeVersion": "10.0.0",
"version": "1.0.1"
}