From b3fd39843288c37a362933c5157b830f3ce33efa Mon Sep 17 00:00:00 2001 From: Krzysztof Kuran Date: Wed, 11 Dec 2024 16:39:41 +0100 Subject: [PATCH] Change emoticons --- README.md | 2 +- bin/index.js | 3614 ++++++++++++++++++++++----------------------- src/html/index.ts | 6 +- 3 files changed, 1811 insertions(+), 1811 deletions(-) diff --git a/README.md b/README.md index 0ac8865..fae9485 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Coverage report for commit: `9f99ed3` File: `clover.example.base.xml` -
Summary - Lines: 87.97% :arrow_down_small: | Methods: 81.05% :arrow_up_small:
FilesLinesMethodsBranches
src/main/php/PHPMD
   AbstractNode.php86.05%70.59%-
   AbstractRenderer.php100.00%100.00%-
   AbstractRule.php80.00%72.00%-
   PHPMD.php90.32%75.00%-
   Parser.php89.19%92.86%-
   ParserFactory.php90.63%71.43%-
   ProcessingError.php100.00%100.00%-
   Report.php100.00%100.00%-
   RuleSet.php87.10%71.43%-
   RuleSetFactory.php96.32%86.36%-
   RuleViolation.php73.33%33.33%-
src/main/php/PHPMD/Baseline
   BaselineFileFinder.php100.00%100.00%-
   BaselineSet.php100.00%100.00%-
   BaselineSetFactory.php100.00%100.00%-
   BaselineValidator.php100.00%100.00%-
   ViolationBaseline.php100.00%100.00%-
src/main/php/PHPMD/Exception
   RuleClassFileNotFoundException.php100.00%100.00%-
   RuleClassNotFoundException.php100.00%100.00%-
   RuleSetNotFoundException.php100.00%100.00%-
src/main/php/PHPMD/Node
   ASTNode.php100.00%100.00%-
   AbstractCallableNode.php100.00%100.00%-
   AbstractNode.php100.00%100.00%-
   AbstractTypeNode.php100.00%100.00%-
   Annotation.php100.00%100.00%-
   Annotations.php100.00%100.00%-
   ClassNode.php100.00%100.00%-
   FunctionNode.php50.00%50.00%-
   InterfaceNode.php100.00%100.00%-
   MethodNode.php100.00%100.00%-
   TraitNode.php100.00%100.00%-
src/main/php/PHPMD/Renderer
   BaselineRenderer.php100.00%100.00%-
   GitHubRenderer.php100.00%100.00%-
   HTMLRenderer.php85.71%63.64%-
   JSONRenderer.php100.00%100.00%-
   RendererFactory.php100.00%100.00%-
   SARIFRenderer.php98.36%80.00%-
   TextRenderer.php100.00%100.00%-
   XMLRenderer.php100.00%100.00%-
src/main/php/PHPMD/Rule
   AbstractLocalVariable.php87.32%69.23%-
   CyclomaticComplexity.php100.00%100.00%-
   ExcessivePublicCount.php100.00%100.00%-
   UnusedFormalParameter.php100.00%100.00%-
   UnusedLocalVariable.php96.92%84.62%-
   UnusedPrivateField.php97.67%88.89%-
   UnusedPrivateMethod.php100.00%100.00%-
src/main/php/PHPMD/Rule/CleanCode
   DuplicatedArrayKey.php84.38%50.00%-
   ElseExpression.php90.00%66.67%-
   ErrorControlOperator.php100.00%100.00%-
   IfStatementAssignment.php95.00%80.00%-
   MissingImport.php93.75%66.67%-
   StaticAccess.php100.00%100.00%-
   UndefinedVariable.php88.00%64.29%-
src/main/php/PHPMD/Rule/Controversial
   CamelCaseMethodName.php100.00%100.00%-
   CamelCaseParameterName.php100.00%100.00%-
   CamelCasePropertyName.php100.00%100.00%-
   CamelCaseVariableName.php93.75%50.00%-
src/main/php/PHPMD/Rule/Design
   CountInLoopExpression.php93.33%80.00%-
   CouplingBetweenObjects.php100.00%100.00%-
   DepthOfInheritance.php92.86%0.00%-
   DevelopmentCodeFragment.php100.00%100.00%-
   EmptyCatchBlock.php100.00%100.00%-
   EvalExpression.php100.00%100.00%-
   ExitExpression.php100.00%100.00%-
   GotoStatement.php100.00%100.00%-
   LongClass.php100.00%100.00%-
   LongMethod.php100.00%100.00%-
   LongParameterList.php100.00%100.00%-
   NpathComplexity.php100.00%100.00%-
   NumberOfChildren.php100.00%100.00%-
   TooManyFields.php100.00%100.00%-
   TooManyMethods.php100.00%100.00%-
   TooManyPublicMethods.php100.00%100.00%-
   WeightedMethodCount.php100.00%100.00%-
src/main/php/PHPMD/Rule/Naming
   BooleanGetMethodName.php100.00%100.00%-
   ConstantNamingConventions.php100.00%100.00%-
   ConstructorWithNameAsEnclosingClass.php88.89%0.00%-
   LongClassName.php100.00%100.00%-
   LongVariable.php100.00%100.00%-
   ShortClassName.php100.00%100.00%-
   ShortMethodName.php100.00%100.00%-
   ShortVariable.php96.92%92.31%-
src/main/php/PHPMD/TextUI
   Command.php100.00%100.00%-
   CommandLineOptions.php71.43%77.42%-
src/main/php/PHPMD/Utility
   Paths.php100.00%100.00%-
   Strings.php100.00%100.00%-
+
Summary - Lines: 87.97% :arrow_lower_left: | Methods: 81.05% :arrow_upper_right:
FilesLinesMethodsBranches
src/main/php/PHPMD
   AbstractNode.php86.05%70.59%-
   AbstractRenderer.php100.00%100.00%-
   AbstractRule.php80.00%72.00%-
   PHPMD.php90.32%75.00%-
   Parser.php89.19%92.86%-
   ParserFactory.php90.63%71.43%-
   ProcessingError.php100.00%100.00%-
   Report.php100.00%100.00%-
   RuleSet.php87.10%71.43%-
   RuleSetFactory.php96.32%86.36%-
   RuleViolation.php73.33%33.33%-
src/main/php/PHPMD/Baseline
   BaselineFileFinder.php100.00%100.00%-
   BaselineSet.php100.00%100.00%-
   BaselineSetFactory.php100.00%100.00%-
   BaselineValidator.php100.00%100.00%-
   ViolationBaseline.php100.00%100.00%-
src/main/php/PHPMD/Exception
   RuleClassFileNotFoundException.php100.00%100.00%-
   RuleClassNotFoundException.php100.00%100.00%-
   RuleSetNotFoundException.php100.00%100.00%-
src/main/php/PHPMD/Node
   ASTNode.php100.00%100.00%-
   AbstractCallableNode.php100.00%100.00%-
   AbstractNode.php100.00%100.00%-
   AbstractTypeNode.php100.00%100.00%-
   Annotation.php100.00%100.00%-
   Annotations.php100.00%100.00%-
   ClassNode.php100.00%100.00%-
   FunctionNode.php50.00%50.00%-
   InterfaceNode.php100.00%100.00%-
   MethodNode.php100.00%100.00%-
   TraitNode.php100.00%100.00%-
src/main/php/PHPMD/Renderer
   BaselineRenderer.php100.00%100.00%-
   GitHubRenderer.php100.00%100.00%-
   HTMLRenderer.php85.71%63.64%-
   JSONRenderer.php100.00%100.00%-
   RendererFactory.php100.00%100.00%-
   SARIFRenderer.php98.36%80.00%-
   TextRenderer.php100.00%100.00%-
   XMLRenderer.php100.00%100.00%-
src/main/php/PHPMD/Rule
   AbstractLocalVariable.php87.32%69.23%-
   CyclomaticComplexity.php100.00%100.00%-
   ExcessivePublicCount.php100.00%100.00%-
   UnusedFormalParameter.php100.00%100.00%-
   UnusedLocalVariable.php96.92%84.62%-
   UnusedPrivateField.php97.67%88.89%-
   UnusedPrivateMethod.php100.00%100.00%-
src/main/php/PHPMD/Rule/CleanCode
   DuplicatedArrayKey.php84.38%50.00%-
   ElseExpression.php90.00%66.67%-
   ErrorControlOperator.php100.00%100.00%-
   IfStatementAssignment.php95.00%80.00%-
   MissingImport.php93.75%66.67%-
   StaticAccess.php100.00%100.00%-
   UndefinedVariable.php88.00%64.29%-
src/main/php/PHPMD/Rule/Controversial
   CamelCaseMethodName.php100.00%100.00%-
   CamelCaseParameterName.php100.00%100.00%-
   CamelCasePropertyName.php100.00%100.00%-
   CamelCaseVariableName.php93.75%50.00%-
src/main/php/PHPMD/Rule/Design
   CountInLoopExpression.php93.33%80.00%-
   CouplingBetweenObjects.php100.00%100.00%-
   DepthOfInheritance.php92.86%0.00%-
   DevelopmentCodeFragment.php100.00%100.00%-
   EmptyCatchBlock.php100.00%100.00%-
   EvalExpression.php100.00%100.00%-
   ExitExpression.php100.00%100.00%-
   GotoStatement.php100.00%100.00%-
   LongClass.php100.00%100.00%-
   LongMethod.php100.00%100.00%-
   LongParameterList.php100.00%100.00%-
   NpathComplexity.php100.00%100.00%-
   NumberOfChildren.php100.00%100.00%-
   TooManyFields.php100.00%100.00%-
   TooManyMethods.php100.00%100.00%-
   TooManyPublicMethods.php100.00%100.00%-
   WeightedMethodCount.php100.00%100.00%-
src/main/php/PHPMD/Rule/Naming
   BooleanGetMethodName.php100.00%100.00%-
   ConstantNamingConventions.php100.00%100.00%-
   ConstructorWithNameAsEnclosingClass.php88.89%0.00%-
   LongClassName.php100.00%100.00%-
   LongVariable.php100.00%100.00%-
   ShortClassName.php100.00%100.00%-
   ShortMethodName.php100.00%100.00%-
   ShortVariable.php96.92%92.31%-
src/main/php/PHPMD/TextUI
   Command.php100.00%100.00%-
   CommandLineOptions.php71.43%77.42%-
src/main/php/PHPMD/Utility
   Paths.php100.00%100.00%-
   Strings.php100.00%100.00%-
:robot: comment via lucassabreu/comment-coverage-clover diff --git a/bin/index.js b/bin/index.js index e7508e4..e808e33 100644 --- a/bin/index.js +++ b/bin/index.js @@ -16,80 +16,80 @@ var require$$0$3 = require('punycode'); var require$$5 = require('zlib'); var require$$1$2 = require('string_decoder'); -/****************************************************************************** -Copyright (c) Microsoft Corporation. - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted. - -THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH -REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY -AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, -INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM -LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR -OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR -PERFORMANCE OF THIS SOFTWARE. -***************************************************************************** */ -/* global Reflect, Promise */ - - -var __assign = function() { - __assign = Object.assign || function __assign(t) { - for (var s, i = 1, n = arguments.length; i < n; i++) { - s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; - } - return t; - }; - return __assign.apply(this, arguments); -}; - -function __awaiter$1(thisArg, _arguments, P, generator) { - function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } - return new (P || (P = Promise))(function (resolve, reject) { - function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } - function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } - function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } - step((generator = generator.apply(thisArg, _arguments || [])).next()); - }); -} - -function __generator(thisArg, body) { - var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; - return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; - function verb(n) { return function (v) { return step([n, v]); }; } - function step(op) { - if (f) throw new TypeError("Generator is already executing."); - while (_) try { - if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; - if (y = 0, t) op = [op[0] & 2, t.value]; - switch (op[0]) { - case 0: case 1: t = op; break; - case 4: _.label++; return { value: op[1], done: false }; - case 5: _.label++; y = op[1]; op = [0]; continue; - case 7: op = _.ops.pop(); _.trys.pop(); continue; - default: - if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } - if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } - if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } - if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } - if (t[2]) _.ops.pop(); - _.trys.pop(); continue; - } - op = body.call(thisArg, _); - } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } - if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; - } -} - -function __spreadArray(to, from, pack) { - if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { - if (ar || !(i in from)) { - if (!ar) ar = Array.prototype.slice.call(from, 0, i); - ar[i] = from[i]; - } - } - return to.concat(ar || Array.prototype.slice.call(from)); +/****************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */ +/* global Reflect, Promise */ + + +var __assign = function() { + __assign = Object.assign || function __assign(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; + +function __awaiter$1(thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +} + +function __generator(thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +} + +function __spreadArray(to, from, pack) { + if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { + if (ar || !(i in from)) { + if (!ar) ar = Array.prototype.slice.call(from, 0, i); + ar[i] = from[i]; + } + } + return to.concat(ar || Array.prototype.slice.call(from)); } var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; @@ -81502,1300 +81502,1300 @@ tr46.toUnicode = function(domain_name, useSTD3) { tr46.PROCESSING_OPTIONS = PROCESSING_OPTIONS; (function (module) { - const punycode = require$$0$3; - const tr46$1 = tr46; - - const specialSchemes = { - ftp: 21, - file: null, - gopher: 70, - http: 80, - https: 443, - ws: 80, - wss: 443 - }; - - const failure = Symbol("failure"); - - function countSymbols(str) { - return punycode.ucs2.decode(str).length; - } - - function at(input, idx) { - const c = input[idx]; - return isNaN(c) ? undefined : String.fromCodePoint(c); - } - - function isASCIIDigit(c) { - return c >= 0x30 && c <= 0x39; - } - - function isASCIIAlpha(c) { - return (c >= 0x41 && c <= 0x5A) || (c >= 0x61 && c <= 0x7A); - } - - function isASCIIAlphanumeric(c) { - return isASCIIAlpha(c) || isASCIIDigit(c); - } - - function isASCIIHex(c) { - return isASCIIDigit(c) || (c >= 0x41 && c <= 0x46) || (c >= 0x61 && c <= 0x66); - } - - function isSingleDot(buffer) { - return buffer === "." || buffer.toLowerCase() === "%2e"; - } - - function isDoubleDot(buffer) { - buffer = buffer.toLowerCase(); - return buffer === ".." || buffer === "%2e." || buffer === ".%2e" || buffer === "%2e%2e"; - } - - function isWindowsDriveLetterCodePoints(cp1, cp2) { - return isASCIIAlpha(cp1) && (cp2 === 58 || cp2 === 124); - } - - function isWindowsDriveLetterString(string) { - return string.length === 2 && isASCIIAlpha(string.codePointAt(0)) && (string[1] === ":" || string[1] === "|"); - } - - function isNormalizedWindowsDriveLetterString(string) { - return string.length === 2 && isASCIIAlpha(string.codePointAt(0)) && string[1] === ":"; - } - - function containsForbiddenHostCodePoint(string) { - return string.search(/\u0000|\u0009|\u000A|\u000D|\u0020|#|%|\/|:|\?|@|\[|\\|\]/) !== -1; - } - - function containsForbiddenHostCodePointExcludingPercent(string) { - return string.search(/\u0000|\u0009|\u000A|\u000D|\u0020|#|\/|:|\?|@|\[|\\|\]/) !== -1; - } - - function isSpecialScheme(scheme) { - return specialSchemes[scheme] !== undefined; - } - - function isSpecial(url) { - return isSpecialScheme(url.scheme); - } - - function defaultPort(scheme) { - return specialSchemes[scheme]; - } - - function percentEncode(c) { - let hex = c.toString(16).toUpperCase(); - if (hex.length === 1) { - hex = "0" + hex; - } - - return "%" + hex; - } - - function utf8PercentEncode(c) { - const buf = new Buffer(c); - - let str = ""; - - for (let i = 0; i < buf.length; ++i) { - str += percentEncode(buf[i]); - } - - return str; - } - - function utf8PercentDecode(str) { - const input = new Buffer(str); - const output = []; - for (let i = 0; i < input.length; ++i) { - if (input[i] !== 37) { - output.push(input[i]); - } else if (input[i] === 37 && isASCIIHex(input[i + 1]) && isASCIIHex(input[i + 2])) { - output.push(parseInt(input.slice(i + 1, i + 3).toString(), 16)); - i += 2; - } else { - output.push(input[i]); - } - } - return new Buffer(output).toString(); - } - - function isC0ControlPercentEncode(c) { - return c <= 0x1F || c > 0x7E; - } - - const extraPathPercentEncodeSet = new Set([32, 34, 35, 60, 62, 63, 96, 123, 125]); - function isPathPercentEncode(c) { - return isC0ControlPercentEncode(c) || extraPathPercentEncodeSet.has(c); - } - - const extraUserinfoPercentEncodeSet = - new Set([47, 58, 59, 61, 64, 91, 92, 93, 94, 124]); - function isUserinfoPercentEncode(c) { - return isPathPercentEncode(c) || extraUserinfoPercentEncodeSet.has(c); - } - - function percentEncodeChar(c, encodeSetPredicate) { - const cStr = String.fromCodePoint(c); - - if (encodeSetPredicate(c)) { - return utf8PercentEncode(cStr); - } - - return cStr; - } - - function parseIPv4Number(input) { - let R = 10; - - if (input.length >= 2 && input.charAt(0) === "0" && input.charAt(1).toLowerCase() === "x") { - input = input.substring(2); - R = 16; - } else if (input.length >= 2 && input.charAt(0) === "0") { - input = input.substring(1); - R = 8; - } - - if (input === "") { - return 0; - } - - const regex = R === 10 ? /[^0-9]/ : (R === 16 ? /[^0-9A-Fa-f]/ : /[^0-7]/); - if (regex.test(input)) { - return failure; - } - - return parseInt(input, R); - } - - function parseIPv4(input) { - const parts = input.split("."); - if (parts[parts.length - 1] === "") { - if (parts.length > 1) { - parts.pop(); - } - } - - if (parts.length > 4) { - return input; - } - - const numbers = []; - for (const part of parts) { - if (part === "") { - return input; - } - const n = parseIPv4Number(part); - if (n === failure) { - return input; - } - - numbers.push(n); - } - - for (let i = 0; i < numbers.length - 1; ++i) { - if (numbers[i] > 255) { - return failure; - } - } - if (numbers[numbers.length - 1] >= Math.pow(256, 5 - numbers.length)) { - return failure; - } - - let ipv4 = numbers.pop(); - let counter = 0; - - for (const n of numbers) { - ipv4 += n * Math.pow(256, 3 - counter); - ++counter; - } - - return ipv4; - } - - function serializeIPv4(address) { - let output = ""; - let n = address; - - for (let i = 1; i <= 4; ++i) { - output = String(n % 256) + output; - if (i !== 4) { - output = "." + output; - } - n = Math.floor(n / 256); - } - - return output; - } - - function parseIPv6(input) { - const address = [0, 0, 0, 0, 0, 0, 0, 0]; - let pieceIndex = 0; - let compress = null; - let pointer = 0; - - input = punycode.ucs2.decode(input); - - if (input[pointer] === 58) { - if (input[pointer + 1] !== 58) { - return failure; - } - - pointer += 2; - ++pieceIndex; - compress = pieceIndex; - } - - while (pointer < input.length) { - if (pieceIndex === 8) { - return failure; - } - - if (input[pointer] === 58) { - if (compress !== null) { - return failure; - } - ++pointer; - ++pieceIndex; - compress = pieceIndex; - continue; - } - - let value = 0; - let length = 0; - - while (length < 4 && isASCIIHex(input[pointer])) { - value = value * 0x10 + parseInt(at(input, pointer), 16); - ++pointer; - ++length; - } - - if (input[pointer] === 46) { - if (length === 0) { - return failure; - } - - pointer -= length; - - if (pieceIndex > 6) { - return failure; - } - - let numbersSeen = 0; - - while (input[pointer] !== undefined) { - let ipv4Piece = null; - - if (numbersSeen > 0) { - if (input[pointer] === 46 && numbersSeen < 4) { - ++pointer; - } else { - return failure; - } - } - - if (!isASCIIDigit(input[pointer])) { - return failure; - } - - while (isASCIIDigit(input[pointer])) { - const number = parseInt(at(input, pointer)); - if (ipv4Piece === null) { - ipv4Piece = number; - } else if (ipv4Piece === 0) { - return failure; - } else { - ipv4Piece = ipv4Piece * 10 + number; - } - if (ipv4Piece > 255) { - return failure; - } - ++pointer; - } - - address[pieceIndex] = address[pieceIndex] * 0x100 + ipv4Piece; - - ++numbersSeen; - - if (numbersSeen === 2 || numbersSeen === 4) { - ++pieceIndex; - } - } - - if (numbersSeen !== 4) { - return failure; - } - - break; - } else if (input[pointer] === 58) { - ++pointer; - if (input[pointer] === undefined) { - return failure; - } - } else if (input[pointer] !== undefined) { - return failure; - } - - address[pieceIndex] = value; - ++pieceIndex; - } - - if (compress !== null) { - let swaps = pieceIndex - compress; - pieceIndex = 7; - while (pieceIndex !== 0 && swaps > 0) { - const temp = address[compress + swaps - 1]; - address[compress + swaps - 1] = address[pieceIndex]; - address[pieceIndex] = temp; - --pieceIndex; - --swaps; - } - } else if (compress === null && pieceIndex !== 8) { - return failure; - } - - return address; - } - - function serializeIPv6(address) { - let output = ""; - const seqResult = findLongestZeroSequence(address); - const compress = seqResult.idx; - let ignore0 = false; - - for (let pieceIndex = 0; pieceIndex <= 7; ++pieceIndex) { - if (ignore0 && address[pieceIndex] === 0) { - continue; - } else if (ignore0) { - ignore0 = false; - } - - if (compress === pieceIndex) { - const separator = pieceIndex === 0 ? "::" : ":"; - output += separator; - ignore0 = true; - continue; - } - - output += address[pieceIndex].toString(16); - - if (pieceIndex !== 7) { - output += ":"; - } - } - - return output; - } - - function parseHost(input, isSpecialArg) { - if (input[0] === "[") { - if (input[input.length - 1] !== "]") { - return failure; - } - - return parseIPv6(input.substring(1, input.length - 1)); - } - - if (!isSpecialArg) { - return parseOpaqueHost(input); - } - - const domain = utf8PercentDecode(input); - const asciiDomain = tr46$1.toASCII(domain, false, tr46$1.PROCESSING_OPTIONS.NONTRANSITIONAL, false); - if (asciiDomain === null) { - return failure; - } - - if (containsForbiddenHostCodePoint(asciiDomain)) { - return failure; - } - - const ipv4Host = parseIPv4(asciiDomain); - if (typeof ipv4Host === "number" || ipv4Host === failure) { - return ipv4Host; - } - - return asciiDomain; - } - - function parseOpaqueHost(input) { - if (containsForbiddenHostCodePointExcludingPercent(input)) { - return failure; - } - - let output = ""; - const decoded = punycode.ucs2.decode(input); - for (let i = 0; i < decoded.length; ++i) { - output += percentEncodeChar(decoded[i], isC0ControlPercentEncode); - } - return output; - } - - function findLongestZeroSequence(arr) { - let maxIdx = null; - let maxLen = 1; // only find elements > 1 - let currStart = null; - let currLen = 0; - - for (let i = 0; i < arr.length; ++i) { - if (arr[i] !== 0) { - if (currLen > maxLen) { - maxIdx = currStart; - maxLen = currLen; - } - - currStart = null; - currLen = 0; - } else { - if (currStart === null) { - currStart = i; - } - ++currLen; - } - } - - // if trailing zeros - if (currLen > maxLen) { - maxIdx = currStart; - maxLen = currLen; - } - - return { - idx: maxIdx, - len: maxLen - }; - } - - function serializeHost(host) { - if (typeof host === "number") { - return serializeIPv4(host); - } - - // IPv6 serializer - if (host instanceof Array) { - return "[" + serializeIPv6(host) + "]"; - } - - return host; - } - - function trimControlChars(url) { - return url.replace(/^[\u0000-\u001F\u0020]+|[\u0000-\u001F\u0020]+$/g, ""); - } - - function trimTabAndNewline(url) { - return url.replace(/\u0009|\u000A|\u000D/g, ""); - } - - function shortenPath(url) { - const path = url.path; - if (path.length === 0) { - return; - } - if (url.scheme === "file" && path.length === 1 && isNormalizedWindowsDriveLetter(path[0])) { - return; - } - - path.pop(); - } - - function includesCredentials(url) { - return url.username !== "" || url.password !== ""; - } - - function cannotHaveAUsernamePasswordPort(url) { - return url.host === null || url.host === "" || url.cannotBeABaseURL || url.scheme === "file"; - } - - function isNormalizedWindowsDriveLetter(string) { - return /^[A-Za-z]:$/.test(string); - } - - function URLStateMachine(input, base, encodingOverride, url, stateOverride) { - this.pointer = 0; - this.input = input; - this.base = base || null; - this.encodingOverride = encodingOverride || "utf-8"; - this.stateOverride = stateOverride; - this.url = url; - this.failure = false; - this.parseError = false; - - if (!this.url) { - this.url = { - scheme: "", - username: "", - password: "", - host: null, - port: null, - path: [], - query: null, - fragment: null, - - cannotBeABaseURL: false - }; - - const res = trimControlChars(this.input); - if (res !== this.input) { - this.parseError = true; - } - this.input = res; - } - - const res = trimTabAndNewline(this.input); - if (res !== this.input) { - this.parseError = true; - } - this.input = res; - - this.state = stateOverride || "scheme start"; - - this.buffer = ""; - this.atFlag = false; - this.arrFlag = false; - this.passwordTokenSeenFlag = false; - - this.input = punycode.ucs2.decode(this.input); - - for (; this.pointer <= this.input.length; ++this.pointer) { - const c = this.input[this.pointer]; - const cStr = isNaN(c) ? undefined : String.fromCodePoint(c); - - // exec state machine - const ret = this["parse " + this.state](c, cStr); - if (!ret) { - break; // terminate algorithm - } else if (ret === failure) { - this.failure = true; - break; - } - } - } - - URLStateMachine.prototype["parse scheme start"] = function parseSchemeStart(c, cStr) { - if (isASCIIAlpha(c)) { - this.buffer += cStr.toLowerCase(); - this.state = "scheme"; - } else if (!this.stateOverride) { - this.state = "no scheme"; - --this.pointer; - } else { - this.parseError = true; - return failure; - } - - return true; - }; - - URLStateMachine.prototype["parse scheme"] = function parseScheme(c, cStr) { - if (isASCIIAlphanumeric(c) || c === 43 || c === 45 || c === 46) { - this.buffer += cStr.toLowerCase(); - } else if (c === 58) { - if (this.stateOverride) { - if (isSpecial(this.url) && !isSpecialScheme(this.buffer)) { - return false; - } - - if (!isSpecial(this.url) && isSpecialScheme(this.buffer)) { - return false; - } - - if ((includesCredentials(this.url) || this.url.port !== null) && this.buffer === "file") { - return false; - } - - if (this.url.scheme === "file" && (this.url.host === "" || this.url.host === null)) { - return false; - } - } - this.url.scheme = this.buffer; - this.buffer = ""; - if (this.stateOverride) { - return false; - } - if (this.url.scheme === "file") { - if (this.input[this.pointer + 1] !== 47 || this.input[this.pointer + 2] !== 47) { - this.parseError = true; - } - this.state = "file"; - } else if (isSpecial(this.url) && this.base !== null && this.base.scheme === this.url.scheme) { - this.state = "special relative or authority"; - } else if (isSpecial(this.url)) { - this.state = "special authority slashes"; - } else if (this.input[this.pointer + 1] === 47) { - this.state = "path or authority"; - ++this.pointer; - } else { - this.url.cannotBeABaseURL = true; - this.url.path.push(""); - this.state = "cannot-be-a-base-URL path"; - } - } else if (!this.stateOverride) { - this.buffer = ""; - this.state = "no scheme"; - this.pointer = -1; - } else { - this.parseError = true; - return failure; - } - - return true; - }; - - URLStateMachine.prototype["parse no scheme"] = function parseNoScheme(c) { - if (this.base === null || (this.base.cannotBeABaseURL && c !== 35)) { - return failure; - } else if (this.base.cannotBeABaseURL && c === 35) { - this.url.scheme = this.base.scheme; - this.url.path = this.base.path.slice(); - this.url.query = this.base.query; - this.url.fragment = ""; - this.url.cannotBeABaseURL = true; - this.state = "fragment"; - } else if (this.base.scheme === "file") { - this.state = "file"; - --this.pointer; - } else { - this.state = "relative"; - --this.pointer; - } - - return true; - }; - - URLStateMachine.prototype["parse special relative or authority"] = function parseSpecialRelativeOrAuthority(c) { - if (c === 47 && this.input[this.pointer + 1] === 47) { - this.state = "special authority ignore slashes"; - ++this.pointer; - } else { - this.parseError = true; - this.state = "relative"; - --this.pointer; - } - - return true; - }; - - URLStateMachine.prototype["parse path or authority"] = function parsePathOrAuthority(c) { - if (c === 47) { - this.state = "authority"; - } else { - this.state = "path"; - --this.pointer; - } - - return true; - }; - - URLStateMachine.prototype["parse relative"] = function parseRelative(c) { - this.url.scheme = this.base.scheme; - if (isNaN(c)) { - this.url.username = this.base.username; - this.url.password = this.base.password; - this.url.host = this.base.host; - this.url.port = this.base.port; - this.url.path = this.base.path.slice(); - this.url.query = this.base.query; - } else if (c === 47) { - this.state = "relative slash"; - } else if (c === 63) { - this.url.username = this.base.username; - this.url.password = this.base.password; - this.url.host = this.base.host; - this.url.port = this.base.port; - this.url.path = this.base.path.slice(); - this.url.query = ""; - this.state = "query"; - } else if (c === 35) { - this.url.username = this.base.username; - this.url.password = this.base.password; - this.url.host = this.base.host; - this.url.port = this.base.port; - this.url.path = this.base.path.slice(); - this.url.query = this.base.query; - this.url.fragment = ""; - this.state = "fragment"; - } else if (isSpecial(this.url) && c === 92) { - this.parseError = true; - this.state = "relative slash"; - } else { - this.url.username = this.base.username; - this.url.password = this.base.password; - this.url.host = this.base.host; - this.url.port = this.base.port; - this.url.path = this.base.path.slice(0, this.base.path.length - 1); - - this.state = "path"; - --this.pointer; - } - - return true; - }; - - URLStateMachine.prototype["parse relative slash"] = function parseRelativeSlash(c) { - if (isSpecial(this.url) && (c === 47 || c === 92)) { - if (c === 92) { - this.parseError = true; - } - this.state = "special authority ignore slashes"; - } else if (c === 47) { - this.state = "authority"; - } else { - this.url.username = this.base.username; - this.url.password = this.base.password; - this.url.host = this.base.host; - this.url.port = this.base.port; - this.state = "path"; - --this.pointer; - } - - return true; - }; - - URLStateMachine.prototype["parse special authority slashes"] = function parseSpecialAuthoritySlashes(c) { - if (c === 47 && this.input[this.pointer + 1] === 47) { - this.state = "special authority ignore slashes"; - ++this.pointer; - } else { - this.parseError = true; - this.state = "special authority ignore slashes"; - --this.pointer; - } - - return true; - }; - - URLStateMachine.prototype["parse special authority ignore slashes"] = function parseSpecialAuthorityIgnoreSlashes(c) { - if (c !== 47 && c !== 92) { - this.state = "authority"; - --this.pointer; - } else { - this.parseError = true; - } - - return true; - }; - - URLStateMachine.prototype["parse authority"] = function parseAuthority(c, cStr) { - if (c === 64) { - this.parseError = true; - if (this.atFlag) { - this.buffer = "%40" + this.buffer; - } - this.atFlag = true; - - // careful, this is based on buffer and has its own pointer (this.pointer != pointer) and inner chars - const len = countSymbols(this.buffer); - for (let pointer = 0; pointer < len; ++pointer) { - const codePoint = this.buffer.codePointAt(pointer); - - if (codePoint === 58 && !this.passwordTokenSeenFlag) { - this.passwordTokenSeenFlag = true; - continue; - } - const encodedCodePoints = percentEncodeChar(codePoint, isUserinfoPercentEncode); - if (this.passwordTokenSeenFlag) { - this.url.password += encodedCodePoints; - } else { - this.url.username += encodedCodePoints; - } - } - this.buffer = ""; - } else if (isNaN(c) || c === 47 || c === 63 || c === 35 || - (isSpecial(this.url) && c === 92)) { - if (this.atFlag && this.buffer === "") { - this.parseError = true; - return failure; - } - this.pointer -= countSymbols(this.buffer) + 1; - this.buffer = ""; - this.state = "host"; - } else { - this.buffer += cStr; - } - - return true; - }; - - URLStateMachine.prototype["parse hostname"] = - URLStateMachine.prototype["parse host"] = function parseHostName(c, cStr) { - if (this.stateOverride && this.url.scheme === "file") { - --this.pointer; - this.state = "file host"; - } else if (c === 58 && !this.arrFlag) { - if (this.buffer === "") { - this.parseError = true; - return failure; - } - - const host = parseHost(this.buffer, isSpecial(this.url)); - if (host === failure) { - return failure; - } - - this.url.host = host; - this.buffer = ""; - this.state = "port"; - if (this.stateOverride === "hostname") { - return false; - } - } else if (isNaN(c) || c === 47 || c === 63 || c === 35 || - (isSpecial(this.url) && c === 92)) { - --this.pointer; - if (isSpecial(this.url) && this.buffer === "") { - this.parseError = true; - return failure; - } else if (this.stateOverride && this.buffer === "" && - (includesCredentials(this.url) || this.url.port !== null)) { - this.parseError = true; - return false; - } - - const host = parseHost(this.buffer, isSpecial(this.url)); - if (host === failure) { - return failure; - } - - this.url.host = host; - this.buffer = ""; - this.state = "path start"; - if (this.stateOverride) { - return false; - } - } else { - if (c === 91) { - this.arrFlag = true; - } else if (c === 93) { - this.arrFlag = false; - } - this.buffer += cStr; - } - - return true; - }; - - URLStateMachine.prototype["parse port"] = function parsePort(c, cStr) { - if (isASCIIDigit(c)) { - this.buffer += cStr; - } else if (isNaN(c) || c === 47 || c === 63 || c === 35 || - (isSpecial(this.url) && c === 92) || - this.stateOverride) { - if (this.buffer !== "") { - const port = parseInt(this.buffer); - if (port > Math.pow(2, 16) - 1) { - this.parseError = true; - return failure; - } - this.url.port = port === defaultPort(this.url.scheme) ? null : port; - this.buffer = ""; - } - if (this.stateOverride) { - return false; - } - this.state = "path start"; - --this.pointer; - } else { - this.parseError = true; - return failure; - } - - return true; - }; - - const fileOtherwiseCodePoints = new Set([47, 92, 63, 35]); - - URLStateMachine.prototype["parse file"] = function parseFile(c) { - this.url.scheme = "file"; - - if (c === 47 || c === 92) { - if (c === 92) { - this.parseError = true; - } - this.state = "file slash"; - } else if (this.base !== null && this.base.scheme === "file") { - if (isNaN(c)) { - this.url.host = this.base.host; - this.url.path = this.base.path.slice(); - this.url.query = this.base.query; - } else if (c === 63) { - this.url.host = this.base.host; - this.url.path = this.base.path.slice(); - this.url.query = ""; - this.state = "query"; - } else if (c === 35) { - this.url.host = this.base.host; - this.url.path = this.base.path.slice(); - this.url.query = this.base.query; - this.url.fragment = ""; - this.state = "fragment"; - } else { - if (this.input.length - this.pointer - 1 === 0 || // remaining consists of 0 code points - !isWindowsDriveLetterCodePoints(c, this.input[this.pointer + 1]) || - (this.input.length - this.pointer - 1 >= 2 && // remaining has at least 2 code points - !fileOtherwiseCodePoints.has(this.input[this.pointer + 2]))) { - this.url.host = this.base.host; - this.url.path = this.base.path.slice(); - shortenPath(this.url); - } else { - this.parseError = true; - } - - this.state = "path"; - --this.pointer; - } - } else { - this.state = "path"; - --this.pointer; - } - - return true; - }; - - URLStateMachine.prototype["parse file slash"] = function parseFileSlash(c) { - if (c === 47 || c === 92) { - if (c === 92) { - this.parseError = true; - } - this.state = "file host"; - } else { - if (this.base !== null && this.base.scheme === "file") { - if (isNormalizedWindowsDriveLetterString(this.base.path[0])) { - this.url.path.push(this.base.path[0]); - } else { - this.url.host = this.base.host; - } - } - this.state = "path"; - --this.pointer; - } - - return true; - }; - - URLStateMachine.prototype["parse file host"] = function parseFileHost(c, cStr) { - if (isNaN(c) || c === 47 || c === 92 || c === 63 || c === 35) { - --this.pointer; - if (!this.stateOverride && isWindowsDriveLetterString(this.buffer)) { - this.parseError = true; - this.state = "path"; - } else if (this.buffer === "") { - this.url.host = ""; - if (this.stateOverride) { - return false; - } - this.state = "path start"; - } else { - let host = parseHost(this.buffer, isSpecial(this.url)); - if (host === failure) { - return failure; - } - if (host === "localhost") { - host = ""; - } - this.url.host = host; - - if (this.stateOverride) { - return false; - } - - this.buffer = ""; - this.state = "path start"; - } - } else { - this.buffer += cStr; - } - - return true; - }; - - URLStateMachine.prototype["parse path start"] = function parsePathStart(c) { - if (isSpecial(this.url)) { - if (c === 92) { - this.parseError = true; - } - this.state = "path"; - - if (c !== 47 && c !== 92) { - --this.pointer; - } - } else if (!this.stateOverride && c === 63) { - this.url.query = ""; - this.state = "query"; - } else if (!this.stateOverride && c === 35) { - this.url.fragment = ""; - this.state = "fragment"; - } else if (c !== undefined) { - this.state = "path"; - if (c !== 47) { - --this.pointer; - } - } - - return true; - }; - - URLStateMachine.prototype["parse path"] = function parsePath(c) { - if (isNaN(c) || c === 47 || (isSpecial(this.url) && c === 92) || - (!this.stateOverride && (c === 63 || c === 35))) { - if (isSpecial(this.url) && c === 92) { - this.parseError = true; - } - - if (isDoubleDot(this.buffer)) { - shortenPath(this.url); - if (c !== 47 && !(isSpecial(this.url) && c === 92)) { - this.url.path.push(""); - } - } else if (isSingleDot(this.buffer) && c !== 47 && - !(isSpecial(this.url) && c === 92)) { - this.url.path.push(""); - } else if (!isSingleDot(this.buffer)) { - if (this.url.scheme === "file" && this.url.path.length === 0 && isWindowsDriveLetterString(this.buffer)) { - if (this.url.host !== "" && this.url.host !== null) { - this.parseError = true; - this.url.host = ""; - } - this.buffer = this.buffer[0] + ":"; - } - this.url.path.push(this.buffer); - } - this.buffer = ""; - if (this.url.scheme === "file" && (c === undefined || c === 63 || c === 35)) { - while (this.url.path.length > 1 && this.url.path[0] === "") { - this.parseError = true; - this.url.path.shift(); - } - } - if (c === 63) { - this.url.query = ""; - this.state = "query"; - } - if (c === 35) { - this.url.fragment = ""; - this.state = "fragment"; - } - } else { - // TODO: If c is not a URL code point and not "%", parse error. - - if (c === 37 && - (!isASCIIHex(this.input[this.pointer + 1]) || - !isASCIIHex(this.input[this.pointer + 2]))) { - this.parseError = true; - } - - this.buffer += percentEncodeChar(c, isPathPercentEncode); - } - - return true; - }; - - URLStateMachine.prototype["parse cannot-be-a-base-URL path"] = function parseCannotBeABaseURLPath(c) { - if (c === 63) { - this.url.query = ""; - this.state = "query"; - } else if (c === 35) { - this.url.fragment = ""; - this.state = "fragment"; - } else { - // TODO: Add: not a URL code point - if (!isNaN(c) && c !== 37) { - this.parseError = true; - } - - if (c === 37 && - (!isASCIIHex(this.input[this.pointer + 1]) || - !isASCIIHex(this.input[this.pointer + 2]))) { - this.parseError = true; - } - - if (!isNaN(c)) { - this.url.path[0] = this.url.path[0] + percentEncodeChar(c, isC0ControlPercentEncode); - } - } - - return true; - }; - - URLStateMachine.prototype["parse query"] = function parseQuery(c, cStr) { - if (isNaN(c) || (!this.stateOverride && c === 35)) { - if (!isSpecial(this.url) || this.url.scheme === "ws" || this.url.scheme === "wss") { - this.encodingOverride = "utf-8"; - } - - const buffer = new Buffer(this.buffer); // TODO: Use encoding override instead - for (let i = 0; i < buffer.length; ++i) { - if (buffer[i] < 0x21 || buffer[i] > 0x7E || buffer[i] === 0x22 || buffer[i] === 0x23 || - buffer[i] === 0x3C || buffer[i] === 0x3E) { - this.url.query += percentEncode(buffer[i]); - } else { - this.url.query += String.fromCodePoint(buffer[i]); - } - } - - this.buffer = ""; - if (c === 35) { - this.url.fragment = ""; - this.state = "fragment"; - } - } else { - // TODO: If c is not a URL code point and not "%", parse error. - if (c === 37 && - (!isASCIIHex(this.input[this.pointer + 1]) || - !isASCIIHex(this.input[this.pointer + 2]))) { - this.parseError = true; - } - - this.buffer += cStr; - } - - return true; - }; - - URLStateMachine.prototype["parse fragment"] = function parseFragment(c) { - if (isNaN(c)) ; else if (c === 0x0) { - this.parseError = true; - } else { - // TODO: If c is not a URL code point and not "%", parse error. - if (c === 37 && - (!isASCIIHex(this.input[this.pointer + 1]) || - !isASCIIHex(this.input[this.pointer + 2]))) { - this.parseError = true; - } - - this.url.fragment += percentEncodeChar(c, isC0ControlPercentEncode); - } - - return true; - }; - - function serializeURL(url, excludeFragment) { - let output = url.scheme + ":"; - if (url.host !== null) { - output += "//"; - - if (url.username !== "" || url.password !== "") { - output += url.username; - if (url.password !== "") { - output += ":" + url.password; - } - output += "@"; - } - - output += serializeHost(url.host); - - if (url.port !== null) { - output += ":" + url.port; - } - } else if (url.host === null && url.scheme === "file") { - output += "//"; - } - - if (url.cannotBeABaseURL) { - output += url.path[0]; - } else { - for (const string of url.path) { - output += "/" + string; - } - } - - if (url.query !== null) { - output += "?" + url.query; - } - - if (!excludeFragment && url.fragment !== null) { - output += "#" + url.fragment; - } - - return output; - } - - function serializeOrigin(tuple) { - let result = tuple.scheme + "://"; - result += serializeHost(tuple.host); - - if (tuple.port !== null) { - result += ":" + tuple.port; - } - - return result; - } - - module.exports.serializeURL = serializeURL; - - module.exports.serializeURLOrigin = function (url) { - // https://url.spec.whatwg.org/#concept-url-origin - switch (url.scheme) { - case "blob": - try { - return module.exports.serializeURLOrigin(module.exports.parseURL(url.path[0])); - } catch (e) { - // serializing an opaque origin returns "null" - return "null"; - } - case "ftp": - case "gopher": - case "http": - case "https": - case "ws": - case "wss": - return serializeOrigin({ - scheme: url.scheme, - host: url.host, - port: url.port - }); - case "file": - // spec says "exercise to the reader", chrome says "file://" - return "file://"; - default: - // serializing an opaque origin returns "null" - return "null"; - } - }; - - module.exports.basicURLParse = function (input, options) { - if (options === undefined) { - options = {}; - } - - const usm = new URLStateMachine(input, options.baseURL, options.encodingOverride, options.url, options.stateOverride); - if (usm.failure) { - return "failure"; - } - - return usm.url; - }; - - module.exports.setTheUsername = function (url, username) { - url.username = ""; - const decoded = punycode.ucs2.decode(username); - for (let i = 0; i < decoded.length; ++i) { - url.username += percentEncodeChar(decoded[i], isUserinfoPercentEncode); - } - }; - - module.exports.setThePassword = function (url, password) { - url.password = ""; - const decoded = punycode.ucs2.decode(password); - for (let i = 0; i < decoded.length; ++i) { - url.password += percentEncodeChar(decoded[i], isUserinfoPercentEncode); - } - }; - - module.exports.serializeHost = serializeHost; - - module.exports.cannotHaveAUsernamePasswordPort = cannotHaveAUsernamePasswordPort; - - module.exports.serializeInteger = function (integer) { - return String(integer); - }; - - module.exports.parseURL = function (input, options) { - if (options === undefined) { - options = {}; - } - - // We don't handle blobs, so this just delegates: - return module.exports.basicURLParse(input, { baseURL: options.baseURL, encodingOverride: options.encodingOverride }); + const punycode = require$$0$3; + const tr46$1 = tr46; + + const specialSchemes = { + ftp: 21, + file: null, + gopher: 70, + http: 80, + https: 443, + ws: 80, + wss: 443 + }; + + const failure = Symbol("failure"); + + function countSymbols(str) { + return punycode.ucs2.decode(str).length; + } + + function at(input, idx) { + const c = input[idx]; + return isNaN(c) ? undefined : String.fromCodePoint(c); + } + + function isASCIIDigit(c) { + return c >= 0x30 && c <= 0x39; + } + + function isASCIIAlpha(c) { + return (c >= 0x41 && c <= 0x5A) || (c >= 0x61 && c <= 0x7A); + } + + function isASCIIAlphanumeric(c) { + return isASCIIAlpha(c) || isASCIIDigit(c); + } + + function isASCIIHex(c) { + return isASCIIDigit(c) || (c >= 0x41 && c <= 0x46) || (c >= 0x61 && c <= 0x66); + } + + function isSingleDot(buffer) { + return buffer === "." || buffer.toLowerCase() === "%2e"; + } + + function isDoubleDot(buffer) { + buffer = buffer.toLowerCase(); + return buffer === ".." || buffer === "%2e." || buffer === ".%2e" || buffer === "%2e%2e"; + } + + function isWindowsDriveLetterCodePoints(cp1, cp2) { + return isASCIIAlpha(cp1) && (cp2 === 58 || cp2 === 124); + } + + function isWindowsDriveLetterString(string) { + return string.length === 2 && isASCIIAlpha(string.codePointAt(0)) && (string[1] === ":" || string[1] === "|"); + } + + function isNormalizedWindowsDriveLetterString(string) { + return string.length === 2 && isASCIIAlpha(string.codePointAt(0)) && string[1] === ":"; + } + + function containsForbiddenHostCodePoint(string) { + return string.search(/\u0000|\u0009|\u000A|\u000D|\u0020|#|%|\/|:|\?|@|\[|\\|\]/) !== -1; + } + + function containsForbiddenHostCodePointExcludingPercent(string) { + return string.search(/\u0000|\u0009|\u000A|\u000D|\u0020|#|\/|:|\?|@|\[|\\|\]/) !== -1; + } + + function isSpecialScheme(scheme) { + return specialSchemes[scheme] !== undefined; + } + + function isSpecial(url) { + return isSpecialScheme(url.scheme); + } + + function defaultPort(scheme) { + return specialSchemes[scheme]; + } + + function percentEncode(c) { + let hex = c.toString(16).toUpperCase(); + if (hex.length === 1) { + hex = "0" + hex; + } + + return "%" + hex; + } + + function utf8PercentEncode(c) { + const buf = new Buffer(c); + + let str = ""; + + for (let i = 0; i < buf.length; ++i) { + str += percentEncode(buf[i]); + } + + return str; + } + + function utf8PercentDecode(str) { + const input = new Buffer(str); + const output = []; + for (let i = 0; i < input.length; ++i) { + if (input[i] !== 37) { + output.push(input[i]); + } else if (input[i] === 37 && isASCIIHex(input[i + 1]) && isASCIIHex(input[i + 2])) { + output.push(parseInt(input.slice(i + 1, i + 3).toString(), 16)); + i += 2; + } else { + output.push(input[i]); + } + } + return new Buffer(output).toString(); + } + + function isC0ControlPercentEncode(c) { + return c <= 0x1F || c > 0x7E; + } + + const extraPathPercentEncodeSet = new Set([32, 34, 35, 60, 62, 63, 96, 123, 125]); + function isPathPercentEncode(c) { + return isC0ControlPercentEncode(c) || extraPathPercentEncodeSet.has(c); + } + + const extraUserinfoPercentEncodeSet = + new Set([47, 58, 59, 61, 64, 91, 92, 93, 94, 124]); + function isUserinfoPercentEncode(c) { + return isPathPercentEncode(c) || extraUserinfoPercentEncodeSet.has(c); + } + + function percentEncodeChar(c, encodeSetPredicate) { + const cStr = String.fromCodePoint(c); + + if (encodeSetPredicate(c)) { + return utf8PercentEncode(cStr); + } + + return cStr; + } + + function parseIPv4Number(input) { + let R = 10; + + if (input.length >= 2 && input.charAt(0) === "0" && input.charAt(1).toLowerCase() === "x") { + input = input.substring(2); + R = 16; + } else if (input.length >= 2 && input.charAt(0) === "0") { + input = input.substring(1); + R = 8; + } + + if (input === "") { + return 0; + } + + const regex = R === 10 ? /[^0-9]/ : (R === 16 ? /[^0-9A-Fa-f]/ : /[^0-7]/); + if (regex.test(input)) { + return failure; + } + + return parseInt(input, R); + } + + function parseIPv4(input) { + const parts = input.split("."); + if (parts[parts.length - 1] === "") { + if (parts.length > 1) { + parts.pop(); + } + } + + if (parts.length > 4) { + return input; + } + + const numbers = []; + for (const part of parts) { + if (part === "") { + return input; + } + const n = parseIPv4Number(part); + if (n === failure) { + return input; + } + + numbers.push(n); + } + + for (let i = 0; i < numbers.length - 1; ++i) { + if (numbers[i] > 255) { + return failure; + } + } + if (numbers[numbers.length - 1] >= Math.pow(256, 5 - numbers.length)) { + return failure; + } + + let ipv4 = numbers.pop(); + let counter = 0; + + for (const n of numbers) { + ipv4 += n * Math.pow(256, 3 - counter); + ++counter; + } + + return ipv4; + } + + function serializeIPv4(address) { + let output = ""; + let n = address; + + for (let i = 1; i <= 4; ++i) { + output = String(n % 256) + output; + if (i !== 4) { + output = "." + output; + } + n = Math.floor(n / 256); + } + + return output; + } + + function parseIPv6(input) { + const address = [0, 0, 0, 0, 0, 0, 0, 0]; + let pieceIndex = 0; + let compress = null; + let pointer = 0; + + input = punycode.ucs2.decode(input); + + if (input[pointer] === 58) { + if (input[pointer + 1] !== 58) { + return failure; + } + + pointer += 2; + ++pieceIndex; + compress = pieceIndex; + } + + while (pointer < input.length) { + if (pieceIndex === 8) { + return failure; + } + + if (input[pointer] === 58) { + if (compress !== null) { + return failure; + } + ++pointer; + ++pieceIndex; + compress = pieceIndex; + continue; + } + + let value = 0; + let length = 0; + + while (length < 4 && isASCIIHex(input[pointer])) { + value = value * 0x10 + parseInt(at(input, pointer), 16); + ++pointer; + ++length; + } + + if (input[pointer] === 46) { + if (length === 0) { + return failure; + } + + pointer -= length; + + if (pieceIndex > 6) { + return failure; + } + + let numbersSeen = 0; + + while (input[pointer] !== undefined) { + let ipv4Piece = null; + + if (numbersSeen > 0) { + if (input[pointer] === 46 && numbersSeen < 4) { + ++pointer; + } else { + return failure; + } + } + + if (!isASCIIDigit(input[pointer])) { + return failure; + } + + while (isASCIIDigit(input[pointer])) { + const number = parseInt(at(input, pointer)); + if (ipv4Piece === null) { + ipv4Piece = number; + } else if (ipv4Piece === 0) { + return failure; + } else { + ipv4Piece = ipv4Piece * 10 + number; + } + if (ipv4Piece > 255) { + return failure; + } + ++pointer; + } + + address[pieceIndex] = address[pieceIndex] * 0x100 + ipv4Piece; + + ++numbersSeen; + + if (numbersSeen === 2 || numbersSeen === 4) { + ++pieceIndex; + } + } + + if (numbersSeen !== 4) { + return failure; + } + + break; + } else if (input[pointer] === 58) { + ++pointer; + if (input[pointer] === undefined) { + return failure; + } + } else if (input[pointer] !== undefined) { + return failure; + } + + address[pieceIndex] = value; + ++pieceIndex; + } + + if (compress !== null) { + let swaps = pieceIndex - compress; + pieceIndex = 7; + while (pieceIndex !== 0 && swaps > 0) { + const temp = address[compress + swaps - 1]; + address[compress + swaps - 1] = address[pieceIndex]; + address[pieceIndex] = temp; + --pieceIndex; + --swaps; + } + } else if (compress === null && pieceIndex !== 8) { + return failure; + } + + return address; + } + + function serializeIPv6(address) { + let output = ""; + const seqResult = findLongestZeroSequence(address); + const compress = seqResult.idx; + let ignore0 = false; + + for (let pieceIndex = 0; pieceIndex <= 7; ++pieceIndex) { + if (ignore0 && address[pieceIndex] === 0) { + continue; + } else if (ignore0) { + ignore0 = false; + } + + if (compress === pieceIndex) { + const separator = pieceIndex === 0 ? "::" : ":"; + output += separator; + ignore0 = true; + continue; + } + + output += address[pieceIndex].toString(16); + + if (pieceIndex !== 7) { + output += ":"; + } + } + + return output; + } + + function parseHost(input, isSpecialArg) { + if (input[0] === "[") { + if (input[input.length - 1] !== "]") { + return failure; + } + + return parseIPv6(input.substring(1, input.length - 1)); + } + + if (!isSpecialArg) { + return parseOpaqueHost(input); + } + + const domain = utf8PercentDecode(input); + const asciiDomain = tr46$1.toASCII(domain, false, tr46$1.PROCESSING_OPTIONS.NONTRANSITIONAL, false); + if (asciiDomain === null) { + return failure; + } + + if (containsForbiddenHostCodePoint(asciiDomain)) { + return failure; + } + + const ipv4Host = parseIPv4(asciiDomain); + if (typeof ipv4Host === "number" || ipv4Host === failure) { + return ipv4Host; + } + + return asciiDomain; + } + + function parseOpaqueHost(input) { + if (containsForbiddenHostCodePointExcludingPercent(input)) { + return failure; + } + + let output = ""; + const decoded = punycode.ucs2.decode(input); + for (let i = 0; i < decoded.length; ++i) { + output += percentEncodeChar(decoded[i], isC0ControlPercentEncode); + } + return output; + } + + function findLongestZeroSequence(arr) { + let maxIdx = null; + let maxLen = 1; // only find elements > 1 + let currStart = null; + let currLen = 0; + + for (let i = 0; i < arr.length; ++i) { + if (arr[i] !== 0) { + if (currLen > maxLen) { + maxIdx = currStart; + maxLen = currLen; + } + + currStart = null; + currLen = 0; + } else { + if (currStart === null) { + currStart = i; + } + ++currLen; + } + } + + // if trailing zeros + if (currLen > maxLen) { + maxIdx = currStart; + maxLen = currLen; + } + + return { + idx: maxIdx, + len: maxLen + }; + } + + function serializeHost(host) { + if (typeof host === "number") { + return serializeIPv4(host); + } + + // IPv6 serializer + if (host instanceof Array) { + return "[" + serializeIPv6(host) + "]"; + } + + return host; + } + + function trimControlChars(url) { + return url.replace(/^[\u0000-\u001F\u0020]+|[\u0000-\u001F\u0020]+$/g, ""); + } + + function trimTabAndNewline(url) { + return url.replace(/\u0009|\u000A|\u000D/g, ""); + } + + function shortenPath(url) { + const path = url.path; + if (path.length === 0) { + return; + } + if (url.scheme === "file" && path.length === 1 && isNormalizedWindowsDriveLetter(path[0])) { + return; + } + + path.pop(); + } + + function includesCredentials(url) { + return url.username !== "" || url.password !== ""; + } + + function cannotHaveAUsernamePasswordPort(url) { + return url.host === null || url.host === "" || url.cannotBeABaseURL || url.scheme === "file"; + } + + function isNormalizedWindowsDriveLetter(string) { + return /^[A-Za-z]:$/.test(string); + } + + function URLStateMachine(input, base, encodingOverride, url, stateOverride) { + this.pointer = 0; + this.input = input; + this.base = base || null; + this.encodingOverride = encodingOverride || "utf-8"; + this.stateOverride = stateOverride; + this.url = url; + this.failure = false; + this.parseError = false; + + if (!this.url) { + this.url = { + scheme: "", + username: "", + password: "", + host: null, + port: null, + path: [], + query: null, + fragment: null, + + cannotBeABaseURL: false + }; + + const res = trimControlChars(this.input); + if (res !== this.input) { + this.parseError = true; + } + this.input = res; + } + + const res = trimTabAndNewline(this.input); + if (res !== this.input) { + this.parseError = true; + } + this.input = res; + + this.state = stateOverride || "scheme start"; + + this.buffer = ""; + this.atFlag = false; + this.arrFlag = false; + this.passwordTokenSeenFlag = false; + + this.input = punycode.ucs2.decode(this.input); + + for (; this.pointer <= this.input.length; ++this.pointer) { + const c = this.input[this.pointer]; + const cStr = isNaN(c) ? undefined : String.fromCodePoint(c); + + // exec state machine + const ret = this["parse " + this.state](c, cStr); + if (!ret) { + break; // terminate algorithm + } else if (ret === failure) { + this.failure = true; + break; + } + } + } + + URLStateMachine.prototype["parse scheme start"] = function parseSchemeStart(c, cStr) { + if (isASCIIAlpha(c)) { + this.buffer += cStr.toLowerCase(); + this.state = "scheme"; + } else if (!this.stateOverride) { + this.state = "no scheme"; + --this.pointer; + } else { + this.parseError = true; + return failure; + } + + return true; + }; + + URLStateMachine.prototype["parse scheme"] = function parseScheme(c, cStr) { + if (isASCIIAlphanumeric(c) || c === 43 || c === 45 || c === 46) { + this.buffer += cStr.toLowerCase(); + } else if (c === 58) { + if (this.stateOverride) { + if (isSpecial(this.url) && !isSpecialScheme(this.buffer)) { + return false; + } + + if (!isSpecial(this.url) && isSpecialScheme(this.buffer)) { + return false; + } + + if ((includesCredentials(this.url) || this.url.port !== null) && this.buffer === "file") { + return false; + } + + if (this.url.scheme === "file" && (this.url.host === "" || this.url.host === null)) { + return false; + } + } + this.url.scheme = this.buffer; + this.buffer = ""; + if (this.stateOverride) { + return false; + } + if (this.url.scheme === "file") { + if (this.input[this.pointer + 1] !== 47 || this.input[this.pointer + 2] !== 47) { + this.parseError = true; + } + this.state = "file"; + } else if (isSpecial(this.url) && this.base !== null && this.base.scheme === this.url.scheme) { + this.state = "special relative or authority"; + } else if (isSpecial(this.url)) { + this.state = "special authority slashes"; + } else if (this.input[this.pointer + 1] === 47) { + this.state = "path or authority"; + ++this.pointer; + } else { + this.url.cannotBeABaseURL = true; + this.url.path.push(""); + this.state = "cannot-be-a-base-URL path"; + } + } else if (!this.stateOverride) { + this.buffer = ""; + this.state = "no scheme"; + this.pointer = -1; + } else { + this.parseError = true; + return failure; + } + + return true; + }; + + URLStateMachine.prototype["parse no scheme"] = function parseNoScheme(c) { + if (this.base === null || (this.base.cannotBeABaseURL && c !== 35)) { + return failure; + } else if (this.base.cannotBeABaseURL && c === 35) { + this.url.scheme = this.base.scheme; + this.url.path = this.base.path.slice(); + this.url.query = this.base.query; + this.url.fragment = ""; + this.url.cannotBeABaseURL = true; + this.state = "fragment"; + } else if (this.base.scheme === "file") { + this.state = "file"; + --this.pointer; + } else { + this.state = "relative"; + --this.pointer; + } + + return true; + }; + + URLStateMachine.prototype["parse special relative or authority"] = function parseSpecialRelativeOrAuthority(c) { + if (c === 47 && this.input[this.pointer + 1] === 47) { + this.state = "special authority ignore slashes"; + ++this.pointer; + } else { + this.parseError = true; + this.state = "relative"; + --this.pointer; + } + + return true; + }; + + URLStateMachine.prototype["parse path or authority"] = function parsePathOrAuthority(c) { + if (c === 47) { + this.state = "authority"; + } else { + this.state = "path"; + --this.pointer; + } + + return true; + }; + + URLStateMachine.prototype["parse relative"] = function parseRelative(c) { + this.url.scheme = this.base.scheme; + if (isNaN(c)) { + this.url.username = this.base.username; + this.url.password = this.base.password; + this.url.host = this.base.host; + this.url.port = this.base.port; + this.url.path = this.base.path.slice(); + this.url.query = this.base.query; + } else if (c === 47) { + this.state = "relative slash"; + } else if (c === 63) { + this.url.username = this.base.username; + this.url.password = this.base.password; + this.url.host = this.base.host; + this.url.port = this.base.port; + this.url.path = this.base.path.slice(); + this.url.query = ""; + this.state = "query"; + } else if (c === 35) { + this.url.username = this.base.username; + this.url.password = this.base.password; + this.url.host = this.base.host; + this.url.port = this.base.port; + this.url.path = this.base.path.slice(); + this.url.query = this.base.query; + this.url.fragment = ""; + this.state = "fragment"; + } else if (isSpecial(this.url) && c === 92) { + this.parseError = true; + this.state = "relative slash"; + } else { + this.url.username = this.base.username; + this.url.password = this.base.password; + this.url.host = this.base.host; + this.url.port = this.base.port; + this.url.path = this.base.path.slice(0, this.base.path.length - 1); + + this.state = "path"; + --this.pointer; + } + + return true; + }; + + URLStateMachine.prototype["parse relative slash"] = function parseRelativeSlash(c) { + if (isSpecial(this.url) && (c === 47 || c === 92)) { + if (c === 92) { + this.parseError = true; + } + this.state = "special authority ignore slashes"; + } else if (c === 47) { + this.state = "authority"; + } else { + this.url.username = this.base.username; + this.url.password = this.base.password; + this.url.host = this.base.host; + this.url.port = this.base.port; + this.state = "path"; + --this.pointer; + } + + return true; + }; + + URLStateMachine.prototype["parse special authority slashes"] = function parseSpecialAuthoritySlashes(c) { + if (c === 47 && this.input[this.pointer + 1] === 47) { + this.state = "special authority ignore slashes"; + ++this.pointer; + } else { + this.parseError = true; + this.state = "special authority ignore slashes"; + --this.pointer; + } + + return true; + }; + + URLStateMachine.prototype["parse special authority ignore slashes"] = function parseSpecialAuthorityIgnoreSlashes(c) { + if (c !== 47 && c !== 92) { + this.state = "authority"; + --this.pointer; + } else { + this.parseError = true; + } + + return true; + }; + + URLStateMachine.prototype["parse authority"] = function parseAuthority(c, cStr) { + if (c === 64) { + this.parseError = true; + if (this.atFlag) { + this.buffer = "%40" + this.buffer; + } + this.atFlag = true; + + // careful, this is based on buffer and has its own pointer (this.pointer != pointer) and inner chars + const len = countSymbols(this.buffer); + for (let pointer = 0; pointer < len; ++pointer) { + const codePoint = this.buffer.codePointAt(pointer); + + if (codePoint === 58 && !this.passwordTokenSeenFlag) { + this.passwordTokenSeenFlag = true; + continue; + } + const encodedCodePoints = percentEncodeChar(codePoint, isUserinfoPercentEncode); + if (this.passwordTokenSeenFlag) { + this.url.password += encodedCodePoints; + } else { + this.url.username += encodedCodePoints; + } + } + this.buffer = ""; + } else if (isNaN(c) || c === 47 || c === 63 || c === 35 || + (isSpecial(this.url) && c === 92)) { + if (this.atFlag && this.buffer === "") { + this.parseError = true; + return failure; + } + this.pointer -= countSymbols(this.buffer) + 1; + this.buffer = ""; + this.state = "host"; + } else { + this.buffer += cStr; + } + + return true; + }; + + URLStateMachine.prototype["parse hostname"] = + URLStateMachine.prototype["parse host"] = function parseHostName(c, cStr) { + if (this.stateOverride && this.url.scheme === "file") { + --this.pointer; + this.state = "file host"; + } else if (c === 58 && !this.arrFlag) { + if (this.buffer === "") { + this.parseError = true; + return failure; + } + + const host = parseHost(this.buffer, isSpecial(this.url)); + if (host === failure) { + return failure; + } + + this.url.host = host; + this.buffer = ""; + this.state = "port"; + if (this.stateOverride === "hostname") { + return false; + } + } else if (isNaN(c) || c === 47 || c === 63 || c === 35 || + (isSpecial(this.url) && c === 92)) { + --this.pointer; + if (isSpecial(this.url) && this.buffer === "") { + this.parseError = true; + return failure; + } else if (this.stateOverride && this.buffer === "" && + (includesCredentials(this.url) || this.url.port !== null)) { + this.parseError = true; + return false; + } + + const host = parseHost(this.buffer, isSpecial(this.url)); + if (host === failure) { + return failure; + } + + this.url.host = host; + this.buffer = ""; + this.state = "path start"; + if (this.stateOverride) { + return false; + } + } else { + if (c === 91) { + this.arrFlag = true; + } else if (c === 93) { + this.arrFlag = false; + } + this.buffer += cStr; + } + + return true; + }; + + URLStateMachine.prototype["parse port"] = function parsePort(c, cStr) { + if (isASCIIDigit(c)) { + this.buffer += cStr; + } else if (isNaN(c) || c === 47 || c === 63 || c === 35 || + (isSpecial(this.url) && c === 92) || + this.stateOverride) { + if (this.buffer !== "") { + const port = parseInt(this.buffer); + if (port > Math.pow(2, 16) - 1) { + this.parseError = true; + return failure; + } + this.url.port = port === defaultPort(this.url.scheme) ? null : port; + this.buffer = ""; + } + if (this.stateOverride) { + return false; + } + this.state = "path start"; + --this.pointer; + } else { + this.parseError = true; + return failure; + } + + return true; + }; + + const fileOtherwiseCodePoints = new Set([47, 92, 63, 35]); + + URLStateMachine.prototype["parse file"] = function parseFile(c) { + this.url.scheme = "file"; + + if (c === 47 || c === 92) { + if (c === 92) { + this.parseError = true; + } + this.state = "file slash"; + } else if (this.base !== null && this.base.scheme === "file") { + if (isNaN(c)) { + this.url.host = this.base.host; + this.url.path = this.base.path.slice(); + this.url.query = this.base.query; + } else if (c === 63) { + this.url.host = this.base.host; + this.url.path = this.base.path.slice(); + this.url.query = ""; + this.state = "query"; + } else if (c === 35) { + this.url.host = this.base.host; + this.url.path = this.base.path.slice(); + this.url.query = this.base.query; + this.url.fragment = ""; + this.state = "fragment"; + } else { + if (this.input.length - this.pointer - 1 === 0 || // remaining consists of 0 code points + !isWindowsDriveLetterCodePoints(c, this.input[this.pointer + 1]) || + (this.input.length - this.pointer - 1 >= 2 && // remaining has at least 2 code points + !fileOtherwiseCodePoints.has(this.input[this.pointer + 2]))) { + this.url.host = this.base.host; + this.url.path = this.base.path.slice(); + shortenPath(this.url); + } else { + this.parseError = true; + } + + this.state = "path"; + --this.pointer; + } + } else { + this.state = "path"; + --this.pointer; + } + + return true; + }; + + URLStateMachine.prototype["parse file slash"] = function parseFileSlash(c) { + if (c === 47 || c === 92) { + if (c === 92) { + this.parseError = true; + } + this.state = "file host"; + } else { + if (this.base !== null && this.base.scheme === "file") { + if (isNormalizedWindowsDriveLetterString(this.base.path[0])) { + this.url.path.push(this.base.path[0]); + } else { + this.url.host = this.base.host; + } + } + this.state = "path"; + --this.pointer; + } + + return true; + }; + + URLStateMachine.prototype["parse file host"] = function parseFileHost(c, cStr) { + if (isNaN(c) || c === 47 || c === 92 || c === 63 || c === 35) { + --this.pointer; + if (!this.stateOverride && isWindowsDriveLetterString(this.buffer)) { + this.parseError = true; + this.state = "path"; + } else if (this.buffer === "") { + this.url.host = ""; + if (this.stateOverride) { + return false; + } + this.state = "path start"; + } else { + let host = parseHost(this.buffer, isSpecial(this.url)); + if (host === failure) { + return failure; + } + if (host === "localhost") { + host = ""; + } + this.url.host = host; + + if (this.stateOverride) { + return false; + } + + this.buffer = ""; + this.state = "path start"; + } + } else { + this.buffer += cStr; + } + + return true; + }; + + URLStateMachine.prototype["parse path start"] = function parsePathStart(c) { + if (isSpecial(this.url)) { + if (c === 92) { + this.parseError = true; + } + this.state = "path"; + + if (c !== 47 && c !== 92) { + --this.pointer; + } + } else if (!this.stateOverride && c === 63) { + this.url.query = ""; + this.state = "query"; + } else if (!this.stateOverride && c === 35) { + this.url.fragment = ""; + this.state = "fragment"; + } else if (c !== undefined) { + this.state = "path"; + if (c !== 47) { + --this.pointer; + } + } + + return true; + }; + + URLStateMachine.prototype["parse path"] = function parsePath(c) { + if (isNaN(c) || c === 47 || (isSpecial(this.url) && c === 92) || + (!this.stateOverride && (c === 63 || c === 35))) { + if (isSpecial(this.url) && c === 92) { + this.parseError = true; + } + + if (isDoubleDot(this.buffer)) { + shortenPath(this.url); + if (c !== 47 && !(isSpecial(this.url) && c === 92)) { + this.url.path.push(""); + } + } else if (isSingleDot(this.buffer) && c !== 47 && + !(isSpecial(this.url) && c === 92)) { + this.url.path.push(""); + } else if (!isSingleDot(this.buffer)) { + if (this.url.scheme === "file" && this.url.path.length === 0 && isWindowsDriveLetterString(this.buffer)) { + if (this.url.host !== "" && this.url.host !== null) { + this.parseError = true; + this.url.host = ""; + } + this.buffer = this.buffer[0] + ":"; + } + this.url.path.push(this.buffer); + } + this.buffer = ""; + if (this.url.scheme === "file" && (c === undefined || c === 63 || c === 35)) { + while (this.url.path.length > 1 && this.url.path[0] === "") { + this.parseError = true; + this.url.path.shift(); + } + } + if (c === 63) { + this.url.query = ""; + this.state = "query"; + } + if (c === 35) { + this.url.fragment = ""; + this.state = "fragment"; + } + } else { + // TODO: If c is not a URL code point and not "%", parse error. + + if (c === 37 && + (!isASCIIHex(this.input[this.pointer + 1]) || + !isASCIIHex(this.input[this.pointer + 2]))) { + this.parseError = true; + } + + this.buffer += percentEncodeChar(c, isPathPercentEncode); + } + + return true; + }; + + URLStateMachine.prototype["parse cannot-be-a-base-URL path"] = function parseCannotBeABaseURLPath(c) { + if (c === 63) { + this.url.query = ""; + this.state = "query"; + } else if (c === 35) { + this.url.fragment = ""; + this.state = "fragment"; + } else { + // TODO: Add: not a URL code point + if (!isNaN(c) && c !== 37) { + this.parseError = true; + } + + if (c === 37 && + (!isASCIIHex(this.input[this.pointer + 1]) || + !isASCIIHex(this.input[this.pointer + 2]))) { + this.parseError = true; + } + + if (!isNaN(c)) { + this.url.path[0] = this.url.path[0] + percentEncodeChar(c, isC0ControlPercentEncode); + } + } + + return true; + }; + + URLStateMachine.prototype["parse query"] = function parseQuery(c, cStr) { + if (isNaN(c) || (!this.stateOverride && c === 35)) { + if (!isSpecial(this.url) || this.url.scheme === "ws" || this.url.scheme === "wss") { + this.encodingOverride = "utf-8"; + } + + const buffer = new Buffer(this.buffer); // TODO: Use encoding override instead + for (let i = 0; i < buffer.length; ++i) { + if (buffer[i] < 0x21 || buffer[i] > 0x7E || buffer[i] === 0x22 || buffer[i] === 0x23 || + buffer[i] === 0x3C || buffer[i] === 0x3E) { + this.url.query += percentEncode(buffer[i]); + } else { + this.url.query += String.fromCodePoint(buffer[i]); + } + } + + this.buffer = ""; + if (c === 35) { + this.url.fragment = ""; + this.state = "fragment"; + } + } else { + // TODO: If c is not a URL code point and not "%", parse error. + if (c === 37 && + (!isASCIIHex(this.input[this.pointer + 1]) || + !isASCIIHex(this.input[this.pointer + 2]))) { + this.parseError = true; + } + + this.buffer += cStr; + } + + return true; + }; + + URLStateMachine.prototype["parse fragment"] = function parseFragment(c) { + if (isNaN(c)) ; else if (c === 0x0) { + this.parseError = true; + } else { + // TODO: If c is not a URL code point and not "%", parse error. + if (c === 37 && + (!isASCIIHex(this.input[this.pointer + 1]) || + !isASCIIHex(this.input[this.pointer + 2]))) { + this.parseError = true; + } + + this.url.fragment += percentEncodeChar(c, isC0ControlPercentEncode); + } + + return true; + }; + + function serializeURL(url, excludeFragment) { + let output = url.scheme + ":"; + if (url.host !== null) { + output += "//"; + + if (url.username !== "" || url.password !== "") { + output += url.username; + if (url.password !== "") { + output += ":" + url.password; + } + output += "@"; + } + + output += serializeHost(url.host); + + if (url.port !== null) { + output += ":" + url.port; + } + } else if (url.host === null && url.scheme === "file") { + output += "//"; + } + + if (url.cannotBeABaseURL) { + output += url.path[0]; + } else { + for (const string of url.path) { + output += "/" + string; + } + } + + if (url.query !== null) { + output += "?" + url.query; + } + + if (!excludeFragment && url.fragment !== null) { + output += "#" + url.fragment; + } + + return output; + } + + function serializeOrigin(tuple) { + let result = tuple.scheme + "://"; + result += serializeHost(tuple.host); + + if (tuple.port !== null) { + result += ":" + tuple.port; + } + + return result; + } + + module.exports.serializeURL = serializeURL; + + module.exports.serializeURLOrigin = function (url) { + // https://url.spec.whatwg.org/#concept-url-origin + switch (url.scheme) { + case "blob": + try { + return module.exports.serializeURLOrigin(module.exports.parseURL(url.path[0])); + } catch (e) { + // serializing an opaque origin returns "null" + return "null"; + } + case "ftp": + case "gopher": + case "http": + case "https": + case "ws": + case "wss": + return serializeOrigin({ + scheme: url.scheme, + host: url.host, + port: url.port + }); + case "file": + // spec says "exercise to the reader", chrome says "file://" + return "file://"; + default: + // serializing an opaque origin returns "null" + return "null"; + } + }; + + module.exports.basicURLParse = function (input, options) { + if (options === undefined) { + options = {}; + } + + const usm = new URLStateMachine(input, options.baseURL, options.encodingOverride, options.url, options.stateOverride); + if (usm.failure) { + return "failure"; + } + + return usm.url; + }; + + module.exports.setTheUsername = function (url, username) { + url.username = ""; + const decoded = punycode.ucs2.decode(username); + for (let i = 0; i < decoded.length; ++i) { + url.username += percentEncodeChar(decoded[i], isUserinfoPercentEncode); + } + }; + + module.exports.setThePassword = function (url, password) { + url.password = ""; + const decoded = punycode.ucs2.decode(password); + for (let i = 0; i < decoded.length; ++i) { + url.password += percentEncodeChar(decoded[i], isUserinfoPercentEncode); + } + }; + + module.exports.serializeHost = serializeHost; + + module.exports.cannotHaveAUsernamePasswordPort = cannotHaveAUsernamePasswordPort; + + module.exports.serializeInteger = function (integer) { + return String(integer); + }; + + module.exports.parseURL = function (input, options) { + if (options === undefined) { + options = {}; + } + + // We don't handle blobs, so this just delegates: + return module.exports.basicURLParse(input, { baseURL: options.baseURL, encodingOverride: options.encodingOverride }); }; } (urlStateMachine)); @@ -88627,421 +88627,421 @@ var sax$1 = {}; })(exports); } (sax$1)); -var arrayHelper = { - - isArray: function(value) { - if (Array.isArray) { - return Array.isArray(value); - } - // fallback for older browsers like IE 8 - return Object.prototype.toString.call( value ) === '[object Array]'; - } - +var arrayHelper = { + + isArray: function(value) { + if (Array.isArray) { + return Array.isArray(value); + } + // fallback for older browsers like IE 8 + return Object.prototype.toString.call( value ) === '[object Array]'; + } + }; -var isArray$2 = arrayHelper.isArray; - -var optionsHelper = { - - copyOptions: function (options) { - var key, copy = {}; - for (key in options) { - if (options.hasOwnProperty(key)) { - copy[key] = options[key]; - } - } - return copy; - }, - - ensureFlagExists: function (item, options) { - if (!(item in options) || typeof options[item] !== 'boolean') { - options[item] = false; - } - }, - - ensureSpacesExists: function (options) { - if (!('spaces' in options) || (typeof options.spaces !== 'number' && typeof options.spaces !== 'string')) { - options.spaces = 0; - } - }, - - ensureAlwaysArrayExists: function (options) { - if (!('alwaysArray' in options) || (typeof options.alwaysArray !== 'boolean' && !isArray$2(options.alwaysArray))) { - options.alwaysArray = false; - } - }, - - ensureKeyExists: function (key, options) { - if (!(key + 'Key' in options) || typeof options[key + 'Key'] !== 'string') { - options[key + 'Key'] = options.compact ? '_' + key : key; - } - }, - - checkFnExists: function (key, options) { - return key + 'Fn' in options; - } - +var isArray$2 = arrayHelper.isArray; + +var optionsHelper = { + + copyOptions: function (options) { + var key, copy = {}; + for (key in options) { + if (options.hasOwnProperty(key)) { + copy[key] = options[key]; + } + } + return copy; + }, + + ensureFlagExists: function (item, options) { + if (!(item in options) || typeof options[item] !== 'boolean') { + options[item] = false; + } + }, + + ensureSpacesExists: function (options) { + if (!('spaces' in options) || (typeof options.spaces !== 'number' && typeof options.spaces !== 'string')) { + options.spaces = 0; + } + }, + + ensureAlwaysArrayExists: function (options) { + if (!('alwaysArray' in options) || (typeof options.alwaysArray !== 'boolean' && !isArray$2(options.alwaysArray))) { + options.alwaysArray = false; + } + }, + + ensureKeyExists: function (key, options) { + if (!(key + 'Key' in options) || typeof options[key + 'Key'] !== 'string') { + options[key + 'Key'] = options.compact ? '_' + key : key; + } + }, + + checkFnExists: function (key, options) { + return key + 'Fn' in options; + } + }; -var sax = sax$1; -var helper$2 = optionsHelper; -var isArray$1 = arrayHelper.isArray; - -var options; -var currentElement$1; - -function validateOptions$2(userOptions) { - options = helper$2.copyOptions(userOptions); - helper$2.ensureFlagExists('ignoreDeclaration', options); - helper$2.ensureFlagExists('ignoreInstruction', options); - helper$2.ensureFlagExists('ignoreAttributes', options); - helper$2.ensureFlagExists('ignoreText', options); - helper$2.ensureFlagExists('ignoreComment', options); - helper$2.ensureFlagExists('ignoreCdata', options); - helper$2.ensureFlagExists('ignoreDoctype', options); - helper$2.ensureFlagExists('compact', options); - helper$2.ensureFlagExists('alwaysChildren', options); - helper$2.ensureFlagExists('addParent', options); - helper$2.ensureFlagExists('trim', options); - helper$2.ensureFlagExists('nativeType', options); - helper$2.ensureFlagExists('nativeTypeAttributes', options); - helper$2.ensureFlagExists('sanitize', options); - helper$2.ensureFlagExists('instructionHasAttributes', options); - helper$2.ensureFlagExists('captureSpacesBetweenElements', options); - helper$2.ensureAlwaysArrayExists(options); - helper$2.ensureKeyExists('declaration', options); - helper$2.ensureKeyExists('instruction', options); - helper$2.ensureKeyExists('attributes', options); - helper$2.ensureKeyExists('text', options); - helper$2.ensureKeyExists('comment', options); - helper$2.ensureKeyExists('cdata', options); - helper$2.ensureKeyExists('doctype', options); - helper$2.ensureKeyExists('type', options); - helper$2.ensureKeyExists('name', options); - helper$2.ensureKeyExists('elements', options); - helper$2.ensureKeyExists('parent', options); - return options; -} - -function nativeType(value) { - var nValue = Number(value); - if (!isNaN(nValue)) { - return nValue; - } - var bValue = value.toLowerCase(); - if (bValue === 'true') { - return true; - } else if (bValue === 'false') { - return false; - } - return value; -} - -function addField(type, value) { - var key; - if (options.compact) { - if ( - !currentElement$1[options[type + 'Key']] && - (isArray$1(options.alwaysArray) ? options.alwaysArray.indexOf(options[type + 'Key']) !== -1 : options.alwaysArray) - ) { - currentElement$1[options[type + 'Key']] = []; - } - if (currentElement$1[options[type + 'Key']] && !isArray$1(currentElement$1[options[type + 'Key']])) { - currentElement$1[options[type + 'Key']] = [currentElement$1[options[type + 'Key']]]; - } - if (type + 'Fn' in options && typeof value === 'string') { - value = options[type + 'Fn'](value, currentElement$1); - } - if (type === 'instruction' && ('instructionFn' in options || 'instructionNameFn' in options)) { - for (key in value) { - if (value.hasOwnProperty(key)) { - if ('instructionFn' in options) { - value[key] = options.instructionFn(value[key], key, currentElement$1); - } else { - var temp = value[key]; - delete value[key]; - value[options.instructionNameFn(key, temp, currentElement$1)] = temp; - } - } - } - } - if (isArray$1(currentElement$1[options[type + 'Key']])) { - currentElement$1[options[type + 'Key']].push(value); - } else { - currentElement$1[options[type + 'Key']] = value; - } - } else { - if (!currentElement$1[options.elementsKey]) { - currentElement$1[options.elementsKey] = []; - } - var element = {}; - element[options.typeKey] = type; - if (type === 'instruction') { - for (key in value) { - if (value.hasOwnProperty(key)) { - break; - } - } - element[options.nameKey] = 'instructionNameFn' in options ? options.instructionNameFn(key, value, currentElement$1) : key; - if (options.instructionHasAttributes) { - element[options.attributesKey] = value[key][options.attributesKey]; - if ('instructionFn' in options) { - element[options.attributesKey] = options.instructionFn(element[options.attributesKey], key, currentElement$1); - } - } else { - if ('instructionFn' in options) { - value[key] = options.instructionFn(value[key], key, currentElement$1); - } - element[options.instructionKey] = value[key]; - } - } else { - if (type + 'Fn' in options) { - value = options[type + 'Fn'](value, currentElement$1); - } - element[options[type + 'Key']] = value; - } - if (options.addParent) { - element[options.parentKey] = currentElement$1; - } - currentElement$1[options.elementsKey].push(element); - } -} - -function manipulateAttributes(attributes) { - if ('attributesFn' in options && attributes) { - attributes = options.attributesFn(attributes, currentElement$1); - } - if ((options.trim || 'attributeValueFn' in options || 'attributeNameFn' in options || options.nativeTypeAttributes) && attributes) { - var key; - for (key in attributes) { - if (attributes.hasOwnProperty(key)) { - if (options.trim) attributes[key] = attributes[key].trim(); - if (options.nativeTypeAttributes) { - attributes[key] = nativeType(attributes[key]); - } - if ('attributeValueFn' in options) attributes[key] = options.attributeValueFn(attributes[key], key, currentElement$1); - if ('attributeNameFn' in options) { - var temp = attributes[key]; - delete attributes[key]; - attributes[options.attributeNameFn(key, attributes[key], currentElement$1)] = temp; - } - } - } - } - return attributes; -} - -function onInstruction(instruction) { - var attributes = {}; - if (instruction.body && (instruction.name.toLowerCase() === 'xml' || options.instructionHasAttributes)) { - var attrsRegExp = /([\w:-]+)\s*=\s*(?:"([^"]*)"|'([^']*)'|(\w+))\s*/g; - var match; - while ((match = attrsRegExp.exec(instruction.body)) !== null) { - attributes[match[1]] = match[2] || match[3] || match[4]; - } - attributes = manipulateAttributes(attributes); - } - if (instruction.name.toLowerCase() === 'xml') { - if (options.ignoreDeclaration) { - return; - } - currentElement$1[options.declarationKey] = {}; - if (Object.keys(attributes).length) { - currentElement$1[options.declarationKey][options.attributesKey] = attributes; - } - if (options.addParent) { - currentElement$1[options.declarationKey][options.parentKey] = currentElement$1; - } - } else { - if (options.ignoreInstruction) { - return; - } - if (options.trim) { - instruction.body = instruction.body.trim(); - } - var value = {}; - if (options.instructionHasAttributes && Object.keys(attributes).length) { - value[instruction.name] = {}; - value[instruction.name][options.attributesKey] = attributes; - } else { - value[instruction.name] = instruction.body; - } - addField('instruction', value); - } -} - -function onStartElement(name, attributes) { - var element; - if (typeof name === 'object') { - attributes = name.attributes; - name = name.name; - } - attributes = manipulateAttributes(attributes); - if ('elementNameFn' in options) { - name = options.elementNameFn(name, currentElement$1); - } - if (options.compact) { - element = {}; - if (!options.ignoreAttributes && attributes && Object.keys(attributes).length) { - element[options.attributesKey] = {}; - var key; - for (key in attributes) { - if (attributes.hasOwnProperty(key)) { - element[options.attributesKey][key] = attributes[key]; - } - } - } - if ( - !(name in currentElement$1) && - (isArray$1(options.alwaysArray) ? options.alwaysArray.indexOf(name) !== -1 : options.alwaysArray) - ) { - currentElement$1[name] = []; - } - if (currentElement$1[name] && !isArray$1(currentElement$1[name])) { - currentElement$1[name] = [currentElement$1[name]]; - } - if (isArray$1(currentElement$1[name])) { - currentElement$1[name].push(element); - } else { - currentElement$1[name] = element; - } - } else { - if (!currentElement$1[options.elementsKey]) { - currentElement$1[options.elementsKey] = []; - } - element = {}; - element[options.typeKey] = 'element'; - element[options.nameKey] = name; - if (!options.ignoreAttributes && attributes && Object.keys(attributes).length) { - element[options.attributesKey] = attributes; - } - if (options.alwaysChildren) { - element[options.elementsKey] = []; - } - currentElement$1[options.elementsKey].push(element); - } - element[options.parentKey] = currentElement$1; // will be deleted in onEndElement() if !options.addParent - currentElement$1 = element; -} - -function onText(text) { - if (options.ignoreText) { - return; - } - if (!text.trim() && !options.captureSpacesBetweenElements) { - return; - } - if (options.trim) { - text = text.trim(); - } - if (options.nativeType) { - text = nativeType(text); - } - if (options.sanitize) { - text = text.replace(/&/g, '&').replace(//g, '>'); - } - addField('text', text); -} - -function onComment(comment) { - if (options.ignoreComment) { - return; - } - if (options.trim) { - comment = comment.trim(); - } - addField('comment', comment); -} - -function onEndElement(name) { - var parentElement = currentElement$1[options.parentKey]; - if (!options.addParent) { - delete currentElement$1[options.parentKey]; - } - currentElement$1 = parentElement; -} - -function onCdata(cdata) { - if (options.ignoreCdata) { - return; - } - if (options.trim) { - cdata = cdata.trim(); - } - addField('cdata', cdata); -} - -function onDoctype(doctype) { - if (options.ignoreDoctype) { - return; - } - doctype = doctype.replace(/^ /, ''); - if (options.trim) { - doctype = doctype.trim(); - } - addField('doctype', doctype); -} - -function onError(error) { - error.note = error; //console.error(error); -} - -var xml2js$2 = function (xml, userOptions) { - - var parser = sax.parser(true, {}) ; - var result = {}; - currentElement$1 = result; - - options = validateOptions$2(userOptions); - - { - parser.opt = {strictEntities: true}; - parser.onopentag = onStartElement; - parser.ontext = onText; - parser.oncomment = onComment; - parser.onclosetag = onEndElement; - parser.onerror = onError; - parser.oncdata = onCdata; - parser.ondoctype = onDoctype; - parser.onprocessinginstruction = onInstruction; - } - - { - parser.write(xml).close(); - } - - if (result[options.elementsKey]) { - var temp = result[options.elementsKey]; - delete result[options.elementsKey]; - result[options.elementsKey] = temp; - delete result.text; - } - - return result; - +var sax = sax$1; +var helper$2 = optionsHelper; +var isArray$1 = arrayHelper.isArray; + +var options; +var currentElement$1; + +function validateOptions$2(userOptions) { + options = helper$2.copyOptions(userOptions); + helper$2.ensureFlagExists('ignoreDeclaration', options); + helper$2.ensureFlagExists('ignoreInstruction', options); + helper$2.ensureFlagExists('ignoreAttributes', options); + helper$2.ensureFlagExists('ignoreText', options); + helper$2.ensureFlagExists('ignoreComment', options); + helper$2.ensureFlagExists('ignoreCdata', options); + helper$2.ensureFlagExists('ignoreDoctype', options); + helper$2.ensureFlagExists('compact', options); + helper$2.ensureFlagExists('alwaysChildren', options); + helper$2.ensureFlagExists('addParent', options); + helper$2.ensureFlagExists('trim', options); + helper$2.ensureFlagExists('nativeType', options); + helper$2.ensureFlagExists('nativeTypeAttributes', options); + helper$2.ensureFlagExists('sanitize', options); + helper$2.ensureFlagExists('instructionHasAttributes', options); + helper$2.ensureFlagExists('captureSpacesBetweenElements', options); + helper$2.ensureAlwaysArrayExists(options); + helper$2.ensureKeyExists('declaration', options); + helper$2.ensureKeyExists('instruction', options); + helper$2.ensureKeyExists('attributes', options); + helper$2.ensureKeyExists('text', options); + helper$2.ensureKeyExists('comment', options); + helper$2.ensureKeyExists('cdata', options); + helper$2.ensureKeyExists('doctype', options); + helper$2.ensureKeyExists('type', options); + helper$2.ensureKeyExists('name', options); + helper$2.ensureKeyExists('elements', options); + helper$2.ensureKeyExists('parent', options); + return options; +} + +function nativeType(value) { + var nValue = Number(value); + if (!isNaN(nValue)) { + return nValue; + } + var bValue = value.toLowerCase(); + if (bValue === 'true') { + return true; + } else if (bValue === 'false') { + return false; + } + return value; +} + +function addField(type, value) { + var key; + if (options.compact) { + if ( + !currentElement$1[options[type + 'Key']] && + (isArray$1(options.alwaysArray) ? options.alwaysArray.indexOf(options[type + 'Key']) !== -1 : options.alwaysArray) + ) { + currentElement$1[options[type + 'Key']] = []; + } + if (currentElement$1[options[type + 'Key']] && !isArray$1(currentElement$1[options[type + 'Key']])) { + currentElement$1[options[type + 'Key']] = [currentElement$1[options[type + 'Key']]]; + } + if (type + 'Fn' in options && typeof value === 'string') { + value = options[type + 'Fn'](value, currentElement$1); + } + if (type === 'instruction' && ('instructionFn' in options || 'instructionNameFn' in options)) { + for (key in value) { + if (value.hasOwnProperty(key)) { + if ('instructionFn' in options) { + value[key] = options.instructionFn(value[key], key, currentElement$1); + } else { + var temp = value[key]; + delete value[key]; + value[options.instructionNameFn(key, temp, currentElement$1)] = temp; + } + } + } + } + if (isArray$1(currentElement$1[options[type + 'Key']])) { + currentElement$1[options[type + 'Key']].push(value); + } else { + currentElement$1[options[type + 'Key']] = value; + } + } else { + if (!currentElement$1[options.elementsKey]) { + currentElement$1[options.elementsKey] = []; + } + var element = {}; + element[options.typeKey] = type; + if (type === 'instruction') { + for (key in value) { + if (value.hasOwnProperty(key)) { + break; + } + } + element[options.nameKey] = 'instructionNameFn' in options ? options.instructionNameFn(key, value, currentElement$1) : key; + if (options.instructionHasAttributes) { + element[options.attributesKey] = value[key][options.attributesKey]; + if ('instructionFn' in options) { + element[options.attributesKey] = options.instructionFn(element[options.attributesKey], key, currentElement$1); + } + } else { + if ('instructionFn' in options) { + value[key] = options.instructionFn(value[key], key, currentElement$1); + } + element[options.instructionKey] = value[key]; + } + } else { + if (type + 'Fn' in options) { + value = options[type + 'Fn'](value, currentElement$1); + } + element[options[type + 'Key']] = value; + } + if (options.addParent) { + element[options.parentKey] = currentElement$1; + } + currentElement$1[options.elementsKey].push(element); + } +} + +function manipulateAttributes(attributes) { + if ('attributesFn' in options && attributes) { + attributes = options.attributesFn(attributes, currentElement$1); + } + if ((options.trim || 'attributeValueFn' in options || 'attributeNameFn' in options || options.nativeTypeAttributes) && attributes) { + var key; + for (key in attributes) { + if (attributes.hasOwnProperty(key)) { + if (options.trim) attributes[key] = attributes[key].trim(); + if (options.nativeTypeAttributes) { + attributes[key] = nativeType(attributes[key]); + } + if ('attributeValueFn' in options) attributes[key] = options.attributeValueFn(attributes[key], key, currentElement$1); + if ('attributeNameFn' in options) { + var temp = attributes[key]; + delete attributes[key]; + attributes[options.attributeNameFn(key, attributes[key], currentElement$1)] = temp; + } + } + } + } + return attributes; +} + +function onInstruction(instruction) { + var attributes = {}; + if (instruction.body && (instruction.name.toLowerCase() === 'xml' || options.instructionHasAttributes)) { + var attrsRegExp = /([\w:-]+)\s*=\s*(?:"([^"]*)"|'([^']*)'|(\w+))\s*/g; + var match; + while ((match = attrsRegExp.exec(instruction.body)) !== null) { + attributes[match[1]] = match[2] || match[3] || match[4]; + } + attributes = manipulateAttributes(attributes); + } + if (instruction.name.toLowerCase() === 'xml') { + if (options.ignoreDeclaration) { + return; + } + currentElement$1[options.declarationKey] = {}; + if (Object.keys(attributes).length) { + currentElement$1[options.declarationKey][options.attributesKey] = attributes; + } + if (options.addParent) { + currentElement$1[options.declarationKey][options.parentKey] = currentElement$1; + } + } else { + if (options.ignoreInstruction) { + return; + } + if (options.trim) { + instruction.body = instruction.body.trim(); + } + var value = {}; + if (options.instructionHasAttributes && Object.keys(attributes).length) { + value[instruction.name] = {}; + value[instruction.name][options.attributesKey] = attributes; + } else { + value[instruction.name] = instruction.body; + } + addField('instruction', value); + } +} + +function onStartElement(name, attributes) { + var element; + if (typeof name === 'object') { + attributes = name.attributes; + name = name.name; + } + attributes = manipulateAttributes(attributes); + if ('elementNameFn' in options) { + name = options.elementNameFn(name, currentElement$1); + } + if (options.compact) { + element = {}; + if (!options.ignoreAttributes && attributes && Object.keys(attributes).length) { + element[options.attributesKey] = {}; + var key; + for (key in attributes) { + if (attributes.hasOwnProperty(key)) { + element[options.attributesKey][key] = attributes[key]; + } + } + } + if ( + !(name in currentElement$1) && + (isArray$1(options.alwaysArray) ? options.alwaysArray.indexOf(name) !== -1 : options.alwaysArray) + ) { + currentElement$1[name] = []; + } + if (currentElement$1[name] && !isArray$1(currentElement$1[name])) { + currentElement$1[name] = [currentElement$1[name]]; + } + if (isArray$1(currentElement$1[name])) { + currentElement$1[name].push(element); + } else { + currentElement$1[name] = element; + } + } else { + if (!currentElement$1[options.elementsKey]) { + currentElement$1[options.elementsKey] = []; + } + element = {}; + element[options.typeKey] = 'element'; + element[options.nameKey] = name; + if (!options.ignoreAttributes && attributes && Object.keys(attributes).length) { + element[options.attributesKey] = attributes; + } + if (options.alwaysChildren) { + element[options.elementsKey] = []; + } + currentElement$1[options.elementsKey].push(element); + } + element[options.parentKey] = currentElement$1; // will be deleted in onEndElement() if !options.addParent + currentElement$1 = element; +} + +function onText(text) { + if (options.ignoreText) { + return; + } + if (!text.trim() && !options.captureSpacesBetweenElements) { + return; + } + if (options.trim) { + text = text.trim(); + } + if (options.nativeType) { + text = nativeType(text); + } + if (options.sanitize) { + text = text.replace(/&/g, '&').replace(//g, '>'); + } + addField('text', text); +} + +function onComment(comment) { + if (options.ignoreComment) { + return; + } + if (options.trim) { + comment = comment.trim(); + } + addField('comment', comment); +} + +function onEndElement(name) { + var parentElement = currentElement$1[options.parentKey]; + if (!options.addParent) { + delete currentElement$1[options.parentKey]; + } + currentElement$1 = parentElement; +} + +function onCdata(cdata) { + if (options.ignoreCdata) { + return; + } + if (options.trim) { + cdata = cdata.trim(); + } + addField('cdata', cdata); +} + +function onDoctype(doctype) { + if (options.ignoreDoctype) { + return; + } + doctype = doctype.replace(/^ /, ''); + if (options.trim) { + doctype = doctype.trim(); + } + addField('doctype', doctype); +} + +function onError(error) { + error.note = error; //console.error(error); +} + +var xml2js$2 = function (xml, userOptions) { + + var parser = sax.parser(true, {}) ; + var result = {}; + currentElement$1 = result; + + options = validateOptions$2(userOptions); + + { + parser.opt = {strictEntities: true}; + parser.onopentag = onStartElement; + parser.ontext = onText; + parser.oncomment = onComment; + parser.onclosetag = onEndElement; + parser.onerror = onError; + parser.oncdata = onCdata; + parser.ondoctype = onDoctype; + parser.onprocessinginstruction = onInstruction; + } + + { + parser.write(xml).close(); + } + + if (result[options.elementsKey]) { + var temp = result[options.elementsKey]; + delete result[options.elementsKey]; + result[options.elementsKey] = temp; + delete result.text; + } + + return result; + }; -var helper$1 = optionsHelper; -var xml2js$1 = xml2js$2; - -function validateOptions$1 (userOptions) { - var options = helper$1.copyOptions(userOptions); - helper$1.ensureSpacesExists(options); - return options; -} - -var xml2json$1 = function(xml, userOptions) { - var options, js, json, parentKey; - options = validateOptions$1(userOptions); - js = xml2js$1(xml, options); - parentKey = 'compact' in options && options.compact ? '_parent' : 'parent'; - // parentKey = ptions.compact ? '_parent' : 'parent'; // consider this - if ('addParent' in options && options.addParent) { - json = JSON.stringify(js, function (k, v) { return k === parentKey? '_' : v; }, options.spaces); - } else { - json = JSON.stringify(js, null, options.spaces); - } - return json.replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029'); +var helper$1 = optionsHelper; +var xml2js$1 = xml2js$2; + +function validateOptions$1 (userOptions) { + var options = helper$1.copyOptions(userOptions); + helper$1.ensureSpacesExists(options); + return options; +} + +var xml2json$1 = function(xml, userOptions) { + var options, js, json, parentKey; + options = validateOptions$1(userOptions); + js = xml2js$1(xml, options); + parentKey = 'compact' in options && options.compact ? '_parent' : 'parent'; + // parentKey = ptions.compact ? '_parent' : 'parent'; // consider this + if ('addParent' in options && options.addParent) { + json = JSON.stringify(js, function (k, v) { return k === parentKey? '_' : v; }, options.spaces); + } else { + json = JSON.stringify(js, null, options.spaces); + } + return json.replace(/\u2028/g, '\\u2028').replace(/\u2029/g, '\\u2029'); }; var helper = optionsHelper; @@ -89354,37 +89354,37 @@ var js2xml$2 = function (js, options) { return xml.join(''); }; -var js2xml$1 = js2xml$2; - -var json2xml$1 = function (json, options) { - if (json instanceof Buffer) { - json = json.toString(); - } - var js = null; - if (typeof (json) === 'string') { - try { - js = JSON.parse(json); - } catch (e) { - throw new Error('The JSON structure is invalid'); - } - } else { - js = json; - } - return js2xml$1(js, options); +var js2xml$1 = js2xml$2; + +var json2xml$1 = function (json, options) { + if (json instanceof Buffer) { + json = json.toString(); + } + var js = null; + if (typeof (json) === 'string') { + try { + js = JSON.parse(json); + } catch (e) { + throw new Error('The JSON structure is invalid'); + } + } else { + js = json; + } + return js2xml$1(js, options); }; /*jslint node:true */ -var xml2js = xml2js$2; -var xml2json = xml2json$1; -var js2xml = js2xml$2; -var json2xml = json2xml$1; - -var lib = { - xml2js: xml2js, - xml2json: xml2json, - js2xml: js2xml, - json2xml: json2xml +var xml2js = xml2js$2; +var xml2json = xml2json$1; +var js2xml = js2xml$2; +var json2xml = json2xml$1; + +var lib = { + xml2js: xml2js, + xml2json: xml2json, + js2xml: js2xml, + json2xml: json2xml }; var Coverage = /** @class */ (function () { @@ -89562,10 +89562,10 @@ var line = function (name, m, lang, o, showDelta, showBranchesColumn) { var compare = function (n, o, lang, showDelta) { if (showDelta === void 0) { showDelta = false; } return span(n.percentual == o.percentual - ? ":stop_button:" + ? ":eject_button:" : n.percentual < o.percentual - ? ":arrow_down_small:" - : ":arrow_up_small:", { + ? ":arrow_lower_left:" + : ":arrow_upper_right:", { title: "Was ".concat(p2s(o.percentual || 0, lang, "0%"), " before") + (showDelta && (n.percentual || 0) !== (o.percentual || 0) ? " (".concat(n.percentual > o.percentual ? "+" : "-").concat(p2s(Math.abs(n.percentual - o.percentual), lang), ")") diff --git a/src/html/index.ts b/src/html/index.ts index 7b6428a..ed53bdf 100644 --- a/src/html/index.ts +++ b/src/html/index.ts @@ -101,10 +101,10 @@ const compare = ( ): string => span( n.percentual == o.percentual - ? ":stop_button:" + ? ":eject_button:" : n.percentual < o.percentual - ? ":arrow_down_small:" - : ":arrow_up_small:", + ? ":arrow_lower_left:" + : ":arrow_upper_right:", { title: `Was ${p2s(o.percentual || 0, lang, "0%")} before` +