@zipify/wysiwyg 1.1.1 → 1.2.1-1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/actions/lint-css/action.yaml +1 -3
- package/.release-it.json +2 -1
- package/dist/cli.js +3 -3
- package/dist/wysiwyg.css +24 -25
- package/dist/wysiwyg.mjs +641 -618
- package/jest.config.js +3 -0
- package/lib/components/base/Modal.vue +21 -2
- package/lib/components/base/__tests__/Modal.test.js +1 -0
- package/lib/components/toolbar/controls/link/LinkControl.vue +22 -10
- package/lib/components/toolbar/controls/link/LinkControlHeader.vue +3 -3
- package/lib/components/toolbar/controls/link/__tests__/LinkControl.test.js +8 -8
- package/lib/components/toolbar/controls/link/__tests__/LinkControlHeader.test.js +1 -1
- package/lib/components/toolbar/controls/link/composables/useLink.js +10 -6
- package/lib/composables/__tests__/__snapshots__/useEditor.test.js.snap +1 -1
- package/lib/composables/useEditor.js +4 -3
- package/lib/enums/TextSettings.js +2 -0
- package/lib/extensions/FontStyle.js +2 -2
- package/lib/extensions/FontWeight.js +2 -0
- package/lib/extensions/Link.js +13 -15
- package/lib/extensions/StylePreset.js +33 -3
- package/lib/extensions/TextDecoration.js +6 -12
- package/lib/extensions/__tests__/FontFamily.test.js +7 -6
- package/lib/extensions/__tests__/FontWeight.test.js +19 -10
- package/lib/extensions/__tests__/StylePreset.test.js +52 -2
- package/lib/extensions/__tests__/TextDecoration.test.js +11 -40
- package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +2 -2
- package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +1 -1
- package/lib/extensions/__tests__/__snapshots__/FontColor.test.js.snap +1 -1
- package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +19 -1
- package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +2 -2
- package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +17 -1
- package/lib/extensions/__tests__/__snapshots__/FontWeight.test.js.snap +26 -1
- package/lib/extensions/__tests__/__snapshots__/LineHeight.test.js.snap +2 -2
- package/lib/extensions/__tests__/__snapshots__/Margin.test.js.snap +2 -2
- package/lib/extensions/__tests__/__snapshots__/StylePreset.test.js.snap +22 -2
- package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +3 -46
- package/package.json +22 -22
- package/lib/components/toolbar/controls/link/LinkControlApply.vue +0 -35
- package/node_modules_lambda/acorn-globals/node_modules/.bin/acorn +0 -4
- package/node_modules_lambda/acorn-globals/node_modules/acorn/CHANGELOG.md +0 -620
- package/node_modules_lambda/acorn-globals/node_modules/acorn/LICENSE +0 -21
- package/node_modules_lambda/acorn-globals/node_modules/acorn/README.md +0 -269
- package/node_modules_lambda/acorn-globals/node_modules/acorn/bin/acorn +0 -4
- package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/acorn.d.ts +0 -209
- package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/acorn.js +0 -5186
- package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/acorn.js.map +0 -1
- package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/acorn.mjs +0 -5155
- package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/acorn.mjs.d.ts +0 -2
- package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/acorn.mjs.map +0 -1
- package/node_modules_lambda/acorn-globals/node_modules/acorn/dist/bin.js +0 -64
- package/node_modules_lambda/acorn-globals/node_modules/acorn/package.json +0 -35
- package/node_modules_lambda/cssstyle/node_modules/cssom/LICENSE.txt +0 -20
- package/node_modules_lambda/cssstyle/node_modules/cssom/README.mdown +0 -67
- package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSDocumentRule.js +0 -39
- package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSFontFaceRule.js +0 -36
- package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSHostRule.js +0 -37
- package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSImportRule.js +0 -132
- package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSKeyframeRule.js +0 -37
- package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSKeyframesRule.js +0 -39
- package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSMediaRule.js +0 -41
- package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSOM.js +0 -3
- package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSRule.js +0 -43
- package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSStyleDeclaration.js +0 -148
- package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSStyleRule.js +0 -190
- package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSStyleSheet.js +0 -88
- package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSSupportsRule.js +0 -36
- package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSValue.js +0 -43
- package/node_modules_lambda/cssstyle/node_modules/cssom/lib/CSSValueExpression.js +0 -344
- package/node_modules_lambda/cssstyle/node_modules/cssom/lib/MatcherList.js +0 -62
- package/node_modules_lambda/cssstyle/node_modules/cssom/lib/MediaList.js +0 -61
- package/node_modules_lambda/cssstyle/node_modules/cssom/lib/StyleSheet.js +0 -17
- package/node_modules_lambda/cssstyle/node_modules/cssom/lib/clone.js +0 -82
- package/node_modules_lambda/cssstyle/node_modules/cssom/lib/index.js +0 -21
- package/node_modules_lambda/cssstyle/node_modules/cssom/lib/parse.js +0 -464
- package/node_modules_lambda/cssstyle/node_modules/cssom/package.json +0 -18
- package/node_modules_lambda/data-urls/node_modules/whatwg-url/LICENSE.txt +0 -21
- package/node_modules_lambda/data-urls/node_modules/whatwg-url/README.md +0 -106
- package/node_modules_lambda/data-urls/node_modules/whatwg-url/index.js +0 -27
- package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/Function.js +0 -42
- package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/URL-impl.js +0 -209
- package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/URL.js +0 -442
- package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/URLSearchParams-impl.js +0 -130
- package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/URLSearchParams.js +0 -472
- package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/VoidFunction.js +0 -26
- package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/encoding.js +0 -16
- package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/infra.js +0 -26
- package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/percent-encoding.js +0 -142
- package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/url-state-machine.js +0 -1244
- package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/urlencoded.js +0 -106
- package/node_modules_lambda/data-urls/node_modules/whatwg-url/lib/utils.js +0 -190
- package/node_modules_lambda/data-urls/node_modules/whatwg-url/package.json +0 -58
- package/node_modules_lambda/data-urls/node_modules/whatwg-url/webidl2js-wrapper.js +0 -7
- package/node_modules_lambda/escodegen/node_modules/estraverse/.jshintrc +0 -16
- package/node_modules_lambda/escodegen/node_modules/estraverse/LICENSE.BSD +0 -19
- package/node_modules_lambda/escodegen/node_modules/estraverse/README.md +0 -153
- package/node_modules_lambda/escodegen/node_modules/estraverse/estraverse.js +0 -805
- package/node_modules_lambda/escodegen/node_modules/estraverse/gulpfile.js +0 -70
- package/node_modules_lambda/escodegen/node_modules/estraverse/package.json +0 -40
- package/node_modules_lambda/escodegen/node_modules/levn/LICENSE +0 -22
- package/node_modules_lambda/escodegen/node_modules/levn/README.md +0 -196
- package/node_modules_lambda/escodegen/node_modules/levn/lib/cast.js +0 -298
- package/node_modules_lambda/escodegen/node_modules/levn/lib/coerce.js +0 -285
- package/node_modules_lambda/escodegen/node_modules/levn/lib/index.js +0 -22
- package/node_modules_lambda/escodegen/node_modules/levn/lib/parse-string.js +0 -113
- package/node_modules_lambda/escodegen/node_modules/levn/lib/parse.js +0 -102
- package/node_modules_lambda/escodegen/node_modules/levn/package.json +0 -47
- package/node_modules_lambda/escodegen/node_modules/optionator/CHANGELOG.md +0 -56
- package/node_modules_lambda/escodegen/node_modules/optionator/LICENSE +0 -22
- package/node_modules_lambda/escodegen/node_modules/optionator/README.md +0 -238
- package/node_modules_lambda/escodegen/node_modules/optionator/lib/help.js +0 -260
- package/node_modules_lambda/escodegen/node_modules/optionator/lib/index.js +0 -465
- package/node_modules_lambda/escodegen/node_modules/optionator/lib/util.js +0 -54
- package/node_modules_lambda/escodegen/node_modules/optionator/package.json +0 -44
- package/node_modules_lambda/escodegen/node_modules/prelude-ls/CHANGELOG.md +0 -99
- package/node_modules_lambda/escodegen/node_modules/prelude-ls/LICENSE +0 -22
- package/node_modules_lambda/escodegen/node_modules/prelude-ls/README.md +0 -15
- package/node_modules_lambda/escodegen/node_modules/prelude-ls/lib/Func.js +0 -65
- package/node_modules_lambda/escodegen/node_modules/prelude-ls/lib/List.js +0 -686
- package/node_modules_lambda/escodegen/node_modules/prelude-ls/lib/Num.js +0 -130
- package/node_modules_lambda/escodegen/node_modules/prelude-ls/lib/Obj.js +0 -154
- package/node_modules_lambda/escodegen/node_modules/prelude-ls/lib/Str.js +0 -92
- package/node_modules_lambda/escodegen/node_modules/prelude-ls/lib/index.js +0 -178
- package/node_modules_lambda/escodegen/node_modules/prelude-ls/package.json +0 -52
- package/node_modules_lambda/escodegen/node_modules/source-map/CHANGELOG.md +0 -301
- package/node_modules_lambda/escodegen/node_modules/source-map/LICENSE +0 -28
- package/node_modules_lambda/escodegen/node_modules/source-map/README.md +0 -742
- package/node_modules_lambda/escodegen/node_modules/source-map/dist/source-map.debug.js +0 -3234
- package/node_modules_lambda/escodegen/node_modules/source-map/dist/source-map.js +0 -3233
- package/node_modules_lambda/escodegen/node_modules/source-map/dist/source-map.min.js +0 -2
- package/node_modules_lambda/escodegen/node_modules/source-map/dist/source-map.min.js.map +0 -1
- package/node_modules_lambda/escodegen/node_modules/source-map/lib/array-set.js +0 -121
- package/node_modules_lambda/escodegen/node_modules/source-map/lib/base64-vlq.js +0 -140
- package/node_modules_lambda/escodegen/node_modules/source-map/lib/base64.js +0 -67
- package/node_modules_lambda/escodegen/node_modules/source-map/lib/binary-search.js +0 -111
- package/node_modules_lambda/escodegen/node_modules/source-map/lib/mapping-list.js +0 -79
- package/node_modules_lambda/escodegen/node_modules/source-map/lib/quick-sort.js +0 -114
- package/node_modules_lambda/escodegen/node_modules/source-map/lib/source-map-consumer.js +0 -1145
- package/node_modules_lambda/escodegen/node_modules/source-map/lib/source-map-generator.js +0 -425
- package/node_modules_lambda/escodegen/node_modules/source-map/lib/source-node.js +0 -413
- package/node_modules_lambda/escodegen/node_modules/source-map/lib/util.js +0 -488
- package/node_modules_lambda/escodegen/node_modules/source-map/package.json +0 -73
- package/node_modules_lambda/escodegen/node_modules/source-map/source-map.d.ts +0 -98
- package/node_modules_lambda/escodegen/node_modules/source-map/source-map.js +0 -8
- package/node_modules_lambda/escodegen/node_modules/type-check/LICENSE +0 -22
- package/node_modules_lambda/escodegen/node_modules/type-check/README.md +0 -210
- package/node_modules_lambda/escodegen/node_modules/type-check/lib/check.js +0 -126
- package/node_modules_lambda/escodegen/node_modules/type-check/lib/index.js +0 -16
- package/node_modules_lambda/escodegen/node_modules/type-check/lib/parse-type.js +0 -196
- package/node_modules_lambda/escodegen/node_modules/type-check/package.json +0 -40
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/.github/dependabot.yml +0 -11
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/Changelog.md +0 -212
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/LICENSE +0 -21
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/README.md +0 -130
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/dbcs-codec.js +0 -597
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/dbcs-data.js +0 -188
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/index.js +0 -23
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/internal.js +0 -198
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/sbcs-codec.js +0 -72
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/sbcs-data-generated.js +0 -451
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/sbcs-data.js +0 -179
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/big5-added.json +0 -122
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/cp936.json +0 -264
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/cp949.json +0 -273
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/cp950.json +0 -177
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/eucjp.json +0 -182
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/gb18030-ranges.json +0 -1
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/gbk-added.json +0 -56
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/tables/shiftjis.json +0 -125
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/utf16.js +0 -197
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/utf32.js +0 -319
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/encodings/utf7.js +0 -290
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/lib/bom-handling.js +0 -52
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/lib/index.d.ts +0 -41
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/lib/index.js +0 -180
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/lib/streams.js +0 -109
- package/node_modules_lambda/whatwg-encoding/node_modules/iconv-lite/package.json +0 -44
|
@@ -1,1244 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
const tr46 = require("tr46");
|
|
3
|
-
|
|
4
|
-
const infra = require("./infra");
|
|
5
|
-
const { utf8DecodeWithoutBOM } = require("./encoding");
|
|
6
|
-
const { percentDecodeString, utf8PercentEncodeCodePoint, utf8PercentEncodeString, isC0ControlPercentEncode,
|
|
7
|
-
isFragmentPercentEncode, isQueryPercentEncode, isSpecialQueryPercentEncode, isPathPercentEncode,
|
|
8
|
-
isUserinfoPercentEncode } = require("./percent-encoding");
|
|
9
|
-
|
|
10
|
-
function p(char) {
|
|
11
|
-
return char.codePointAt(0);
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
const specialSchemes = {
|
|
15
|
-
ftp: 21,
|
|
16
|
-
file: null,
|
|
17
|
-
http: 80,
|
|
18
|
-
https: 443,
|
|
19
|
-
ws: 80,
|
|
20
|
-
wss: 443
|
|
21
|
-
};
|
|
22
|
-
|
|
23
|
-
const failure = Symbol("failure");
|
|
24
|
-
|
|
25
|
-
function countSymbols(str) {
|
|
26
|
-
return [...str].length;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function at(input, idx) {
|
|
30
|
-
const c = input[idx];
|
|
31
|
-
return isNaN(c) ? undefined : String.fromCodePoint(c);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function isSingleDot(buffer) {
|
|
35
|
-
return buffer === "." || buffer.toLowerCase() === "%2e";
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function isDoubleDot(buffer) {
|
|
39
|
-
buffer = buffer.toLowerCase();
|
|
40
|
-
return buffer === ".." || buffer === "%2e." || buffer === ".%2e" || buffer === "%2e%2e";
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function isWindowsDriveLetterCodePoints(cp1, cp2) {
|
|
44
|
-
return infra.isASCIIAlpha(cp1) && (cp2 === p(":") || cp2 === p("|"));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function isWindowsDriveLetterString(string) {
|
|
48
|
-
return string.length === 2 && infra.isASCIIAlpha(string.codePointAt(0)) && (string[1] === ":" || string[1] === "|");
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function isNormalizedWindowsDriveLetterString(string) {
|
|
52
|
-
return string.length === 2 && infra.isASCIIAlpha(string.codePointAt(0)) && string[1] === ":";
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function containsForbiddenHostCodePoint(string) {
|
|
56
|
-
return string.search(/\u0000|\u0009|\u000A|\u000D|\u0020|#|%|\/|:|<|>|\?|@|\[|\\|\]|\^|\|/u) !== -1;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
function containsForbiddenHostCodePointExcludingPercent(string) {
|
|
60
|
-
return string.search(/\u0000|\u0009|\u000A|\u000D|\u0020|#|\/|:|<|>|\?|@|\[|\\|\]|\^|\|/u) !== -1;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function isSpecialScheme(scheme) {
|
|
64
|
-
return specialSchemes[scheme] !== undefined;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function isSpecial(url) {
|
|
68
|
-
return isSpecialScheme(url.scheme);
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function isNotSpecial(url) {
|
|
72
|
-
return !isSpecialScheme(url.scheme);
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
function defaultPort(scheme) {
|
|
76
|
-
return specialSchemes[scheme];
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function parseIPv4Number(input) {
|
|
80
|
-
if (input === "") {
|
|
81
|
-
return failure;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
let R = 10;
|
|
85
|
-
|
|
86
|
-
if (input.length >= 2 && input.charAt(0) === "0" && input.charAt(1).toLowerCase() === "x") {
|
|
87
|
-
input = input.substring(2);
|
|
88
|
-
R = 16;
|
|
89
|
-
} else if (input.length >= 2 && input.charAt(0) === "0") {
|
|
90
|
-
input = input.substring(1);
|
|
91
|
-
R = 8;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (input === "") {
|
|
95
|
-
return 0;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
let regex = /[^0-7]/u;
|
|
99
|
-
if (R === 10) {
|
|
100
|
-
regex = /[^0-9]/u;
|
|
101
|
-
}
|
|
102
|
-
if (R === 16) {
|
|
103
|
-
regex = /[^0-9A-Fa-f]/u;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
if (regex.test(input)) {
|
|
107
|
-
return failure;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
return parseInt(input, R);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
function parseIPv4(input) {
|
|
114
|
-
const parts = input.split(".");
|
|
115
|
-
if (parts[parts.length - 1] === "") {
|
|
116
|
-
if (parts.length > 1) {
|
|
117
|
-
parts.pop();
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
if (parts.length > 4) {
|
|
122
|
-
return failure;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const numbers = [];
|
|
126
|
-
for (const part of parts) {
|
|
127
|
-
const n = parseIPv4Number(part);
|
|
128
|
-
if (n === failure) {
|
|
129
|
-
return failure;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
numbers.push(n);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
for (let i = 0; i < numbers.length - 1; ++i) {
|
|
136
|
-
if (numbers[i] > 255) {
|
|
137
|
-
return failure;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
if (numbers[numbers.length - 1] >= 256 ** (5 - numbers.length)) {
|
|
141
|
-
return failure;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
let ipv4 = numbers.pop();
|
|
145
|
-
let counter = 0;
|
|
146
|
-
|
|
147
|
-
for (const n of numbers) {
|
|
148
|
-
ipv4 += n * 256 ** (3 - counter);
|
|
149
|
-
++counter;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return ipv4;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function serializeIPv4(address) {
|
|
156
|
-
let output = "";
|
|
157
|
-
let n = address;
|
|
158
|
-
|
|
159
|
-
for (let i = 1; i <= 4; ++i) {
|
|
160
|
-
output = String(n % 256) + output;
|
|
161
|
-
if (i !== 4) {
|
|
162
|
-
output = `.${output}`;
|
|
163
|
-
}
|
|
164
|
-
n = Math.floor(n / 256);
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
return output;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
function parseIPv6(input) {
|
|
171
|
-
const address = [0, 0, 0, 0, 0, 0, 0, 0];
|
|
172
|
-
let pieceIndex = 0;
|
|
173
|
-
let compress = null;
|
|
174
|
-
let pointer = 0;
|
|
175
|
-
|
|
176
|
-
input = Array.from(input, c => c.codePointAt(0));
|
|
177
|
-
|
|
178
|
-
if (input[pointer] === p(":")) {
|
|
179
|
-
if (input[pointer + 1] !== p(":")) {
|
|
180
|
-
return failure;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
pointer += 2;
|
|
184
|
-
++pieceIndex;
|
|
185
|
-
compress = pieceIndex;
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
while (pointer < input.length) {
|
|
189
|
-
if (pieceIndex === 8) {
|
|
190
|
-
return failure;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
if (input[pointer] === p(":")) {
|
|
194
|
-
if (compress !== null) {
|
|
195
|
-
return failure;
|
|
196
|
-
}
|
|
197
|
-
++pointer;
|
|
198
|
-
++pieceIndex;
|
|
199
|
-
compress = pieceIndex;
|
|
200
|
-
continue;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
let value = 0;
|
|
204
|
-
let length = 0;
|
|
205
|
-
|
|
206
|
-
while (length < 4 && infra.isASCIIHex(input[pointer])) {
|
|
207
|
-
value = value * 0x10 + parseInt(at(input, pointer), 16);
|
|
208
|
-
++pointer;
|
|
209
|
-
++length;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
if (input[pointer] === p(".")) {
|
|
213
|
-
if (length === 0) {
|
|
214
|
-
return failure;
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
pointer -= length;
|
|
218
|
-
|
|
219
|
-
if (pieceIndex > 6) {
|
|
220
|
-
return failure;
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
let numbersSeen = 0;
|
|
224
|
-
|
|
225
|
-
while (input[pointer] !== undefined) {
|
|
226
|
-
let ipv4Piece = null;
|
|
227
|
-
|
|
228
|
-
if (numbersSeen > 0) {
|
|
229
|
-
if (input[pointer] === p(".") && numbersSeen < 4) {
|
|
230
|
-
++pointer;
|
|
231
|
-
} else {
|
|
232
|
-
return failure;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
if (!infra.isASCIIDigit(input[pointer])) {
|
|
237
|
-
return failure;
|
|
238
|
-
}
|
|
239
|
-
|
|
240
|
-
while (infra.isASCIIDigit(input[pointer])) {
|
|
241
|
-
const number = parseInt(at(input, pointer));
|
|
242
|
-
if (ipv4Piece === null) {
|
|
243
|
-
ipv4Piece = number;
|
|
244
|
-
} else if (ipv4Piece === 0) {
|
|
245
|
-
return failure;
|
|
246
|
-
} else {
|
|
247
|
-
ipv4Piece = ipv4Piece * 10 + number;
|
|
248
|
-
}
|
|
249
|
-
if (ipv4Piece > 255) {
|
|
250
|
-
return failure;
|
|
251
|
-
}
|
|
252
|
-
++pointer;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
address[pieceIndex] = address[pieceIndex] * 0x100 + ipv4Piece;
|
|
256
|
-
|
|
257
|
-
++numbersSeen;
|
|
258
|
-
|
|
259
|
-
if (numbersSeen === 2 || numbersSeen === 4) {
|
|
260
|
-
++pieceIndex;
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
if (numbersSeen !== 4) {
|
|
265
|
-
return failure;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
|
-
break;
|
|
269
|
-
} else if (input[pointer] === p(":")) {
|
|
270
|
-
++pointer;
|
|
271
|
-
if (input[pointer] === undefined) {
|
|
272
|
-
return failure;
|
|
273
|
-
}
|
|
274
|
-
} else if (input[pointer] !== undefined) {
|
|
275
|
-
return failure;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
address[pieceIndex] = value;
|
|
279
|
-
++pieceIndex;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
if (compress !== null) {
|
|
283
|
-
let swaps = pieceIndex - compress;
|
|
284
|
-
pieceIndex = 7;
|
|
285
|
-
while (pieceIndex !== 0 && swaps > 0) {
|
|
286
|
-
const temp = address[compress + swaps - 1];
|
|
287
|
-
address[compress + swaps - 1] = address[pieceIndex];
|
|
288
|
-
address[pieceIndex] = temp;
|
|
289
|
-
--pieceIndex;
|
|
290
|
-
--swaps;
|
|
291
|
-
}
|
|
292
|
-
} else if (compress === null && pieceIndex !== 8) {
|
|
293
|
-
return failure;
|
|
294
|
-
}
|
|
295
|
-
|
|
296
|
-
return address;
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
function serializeIPv6(address) {
|
|
300
|
-
let output = "";
|
|
301
|
-
const compress = findLongestZeroSequence(address);
|
|
302
|
-
let ignore0 = false;
|
|
303
|
-
|
|
304
|
-
for (let pieceIndex = 0; pieceIndex <= 7; ++pieceIndex) {
|
|
305
|
-
if (ignore0 && address[pieceIndex] === 0) {
|
|
306
|
-
continue;
|
|
307
|
-
} else if (ignore0) {
|
|
308
|
-
ignore0 = false;
|
|
309
|
-
}
|
|
310
|
-
|
|
311
|
-
if (compress === pieceIndex) {
|
|
312
|
-
const separator = pieceIndex === 0 ? "::" : ":";
|
|
313
|
-
output += separator;
|
|
314
|
-
ignore0 = true;
|
|
315
|
-
continue;
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
output += address[pieceIndex].toString(16);
|
|
319
|
-
|
|
320
|
-
if (pieceIndex !== 7) {
|
|
321
|
-
output += ":";
|
|
322
|
-
}
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
return output;
|
|
326
|
-
}
|
|
327
|
-
|
|
328
|
-
function parseHost(input, isNotSpecialArg = false) {
|
|
329
|
-
if (input[0] === "[") {
|
|
330
|
-
if (input[input.length - 1] !== "]") {
|
|
331
|
-
return failure;
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
return parseIPv6(input.substring(1, input.length - 1));
|
|
335
|
-
}
|
|
336
|
-
|
|
337
|
-
if (isNotSpecialArg) {
|
|
338
|
-
return parseOpaqueHost(input);
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
const domain = utf8DecodeWithoutBOM(percentDecodeString(input));
|
|
342
|
-
const asciiDomain = domainToASCII(domain);
|
|
343
|
-
if (asciiDomain === failure) {
|
|
344
|
-
return failure;
|
|
345
|
-
}
|
|
346
|
-
|
|
347
|
-
if (containsForbiddenHostCodePoint(asciiDomain)) {
|
|
348
|
-
return failure;
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
if (endsInANumber(asciiDomain)) {
|
|
352
|
-
return parseIPv4(asciiDomain);
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
return asciiDomain;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
function endsInANumber(input) {
|
|
359
|
-
const parts = input.split(".");
|
|
360
|
-
if (parts[parts.length - 1] === "") {
|
|
361
|
-
if (parts.length === 1) {
|
|
362
|
-
return false;
|
|
363
|
-
}
|
|
364
|
-
parts.pop();
|
|
365
|
-
}
|
|
366
|
-
|
|
367
|
-
const last = parts[parts.length - 1];
|
|
368
|
-
if (parseIPv4Number(last) !== failure) {
|
|
369
|
-
return true;
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
if (/^[0-9]+$/u.test(last)) {
|
|
373
|
-
return true;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
return false;
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
function parseOpaqueHost(input) {
|
|
380
|
-
if (containsForbiddenHostCodePointExcludingPercent(input)) {
|
|
381
|
-
return failure;
|
|
382
|
-
}
|
|
383
|
-
|
|
384
|
-
return utf8PercentEncodeString(input, isC0ControlPercentEncode);
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
function findLongestZeroSequence(arr) {
|
|
388
|
-
let maxIdx = null;
|
|
389
|
-
let maxLen = 1; // only find elements > 1
|
|
390
|
-
let currStart = null;
|
|
391
|
-
let currLen = 0;
|
|
392
|
-
|
|
393
|
-
for (let i = 0; i < arr.length; ++i) {
|
|
394
|
-
if (arr[i] !== 0) {
|
|
395
|
-
if (currLen > maxLen) {
|
|
396
|
-
maxIdx = currStart;
|
|
397
|
-
maxLen = currLen;
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
currStart = null;
|
|
401
|
-
currLen = 0;
|
|
402
|
-
} else {
|
|
403
|
-
if (currStart === null) {
|
|
404
|
-
currStart = i;
|
|
405
|
-
}
|
|
406
|
-
++currLen;
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
|
|
410
|
-
// if trailing zeros
|
|
411
|
-
if (currLen > maxLen) {
|
|
412
|
-
return currStart;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
return maxIdx;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
function serializeHost(host) {
|
|
419
|
-
if (typeof host === "number") {
|
|
420
|
-
return serializeIPv4(host);
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
// IPv6 serializer
|
|
424
|
-
if (host instanceof Array) {
|
|
425
|
-
return `[${serializeIPv6(host)}]`;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
return host;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
function domainToASCII(domain, beStrict = false) {
|
|
432
|
-
const result = tr46.toASCII(domain, {
|
|
433
|
-
checkBidi: true,
|
|
434
|
-
checkHyphens: false,
|
|
435
|
-
checkJoiners: true,
|
|
436
|
-
useSTD3ASCIIRules: beStrict,
|
|
437
|
-
verifyDNSLength: beStrict
|
|
438
|
-
});
|
|
439
|
-
if (result === null || result === "") {
|
|
440
|
-
return failure;
|
|
441
|
-
}
|
|
442
|
-
return result;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
function trimControlChars(url) {
|
|
446
|
-
return url.replace(/^[\u0000-\u001F\u0020]+|[\u0000-\u001F\u0020]+$/ug, "");
|
|
447
|
-
}
|
|
448
|
-
|
|
449
|
-
function trimTabAndNewline(url) {
|
|
450
|
-
return url.replace(/\u0009|\u000A|\u000D/ug, "");
|
|
451
|
-
}
|
|
452
|
-
|
|
453
|
-
function shortenPath(url) {
|
|
454
|
-
const { path } = url;
|
|
455
|
-
if (path.length === 0) {
|
|
456
|
-
return;
|
|
457
|
-
}
|
|
458
|
-
if (url.scheme === "file" && path.length === 1 && isNormalizedWindowsDriveLetter(path[0])) {
|
|
459
|
-
return;
|
|
460
|
-
}
|
|
461
|
-
|
|
462
|
-
path.pop();
|
|
463
|
-
}
|
|
464
|
-
|
|
465
|
-
function includesCredentials(url) {
|
|
466
|
-
return url.username !== "" || url.password !== "";
|
|
467
|
-
}
|
|
468
|
-
|
|
469
|
-
function cannotHaveAUsernamePasswordPort(url) {
|
|
470
|
-
return url.host === null || url.host === "" || hasAnOpaquePath(url) || url.scheme === "file";
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
function hasAnOpaquePath(url) {
|
|
474
|
-
return typeof url.path === "string";
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
function isNormalizedWindowsDriveLetter(string) {
|
|
478
|
-
return /^[A-Za-z]:$/u.test(string);
|
|
479
|
-
}
|
|
480
|
-
|
|
481
|
-
function URLStateMachine(input, base, encodingOverride, url, stateOverride) {
|
|
482
|
-
this.pointer = 0;
|
|
483
|
-
this.input = input;
|
|
484
|
-
this.base = base || null;
|
|
485
|
-
this.encodingOverride = encodingOverride || "utf-8";
|
|
486
|
-
this.stateOverride = stateOverride;
|
|
487
|
-
this.url = url;
|
|
488
|
-
this.failure = false;
|
|
489
|
-
this.parseError = false;
|
|
490
|
-
|
|
491
|
-
if (!this.url) {
|
|
492
|
-
this.url = {
|
|
493
|
-
scheme: "",
|
|
494
|
-
username: "",
|
|
495
|
-
password: "",
|
|
496
|
-
host: null,
|
|
497
|
-
port: null,
|
|
498
|
-
path: [],
|
|
499
|
-
query: null,
|
|
500
|
-
fragment: null
|
|
501
|
-
};
|
|
502
|
-
|
|
503
|
-
const res = trimControlChars(this.input);
|
|
504
|
-
if (res !== this.input) {
|
|
505
|
-
this.parseError = true;
|
|
506
|
-
}
|
|
507
|
-
this.input = res;
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
const res = trimTabAndNewline(this.input);
|
|
511
|
-
if (res !== this.input) {
|
|
512
|
-
this.parseError = true;
|
|
513
|
-
}
|
|
514
|
-
this.input = res;
|
|
515
|
-
|
|
516
|
-
this.state = stateOverride || "scheme start";
|
|
517
|
-
|
|
518
|
-
this.buffer = "";
|
|
519
|
-
this.atFlag = false;
|
|
520
|
-
this.arrFlag = false;
|
|
521
|
-
this.passwordTokenSeenFlag = false;
|
|
522
|
-
|
|
523
|
-
this.input = Array.from(this.input, c => c.codePointAt(0));
|
|
524
|
-
|
|
525
|
-
for (; this.pointer <= this.input.length; ++this.pointer) {
|
|
526
|
-
const c = this.input[this.pointer];
|
|
527
|
-
const cStr = isNaN(c) ? undefined : String.fromCodePoint(c);
|
|
528
|
-
|
|
529
|
-
// exec state machine
|
|
530
|
-
const ret = this[`parse ${this.state}`](c, cStr);
|
|
531
|
-
if (!ret) {
|
|
532
|
-
break; // terminate algorithm
|
|
533
|
-
} else if (ret === failure) {
|
|
534
|
-
this.failure = true;
|
|
535
|
-
break;
|
|
536
|
-
}
|
|
537
|
-
}
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
URLStateMachine.prototype["parse scheme start"] = function parseSchemeStart(c, cStr) {
|
|
541
|
-
if (infra.isASCIIAlpha(c)) {
|
|
542
|
-
this.buffer += cStr.toLowerCase();
|
|
543
|
-
this.state = "scheme";
|
|
544
|
-
} else if (!this.stateOverride) {
|
|
545
|
-
this.state = "no scheme";
|
|
546
|
-
--this.pointer;
|
|
547
|
-
} else {
|
|
548
|
-
this.parseError = true;
|
|
549
|
-
return failure;
|
|
550
|
-
}
|
|
551
|
-
|
|
552
|
-
return true;
|
|
553
|
-
};
|
|
554
|
-
|
|
555
|
-
URLStateMachine.prototype["parse scheme"] = function parseScheme(c, cStr) {
|
|
556
|
-
if (infra.isASCIIAlphanumeric(c) || c === p("+") || c === p("-") || c === p(".")) {
|
|
557
|
-
this.buffer += cStr.toLowerCase();
|
|
558
|
-
} else if (c === p(":")) {
|
|
559
|
-
if (this.stateOverride) {
|
|
560
|
-
if (isSpecial(this.url) && !isSpecialScheme(this.buffer)) {
|
|
561
|
-
return false;
|
|
562
|
-
}
|
|
563
|
-
|
|
564
|
-
if (!isSpecial(this.url) && isSpecialScheme(this.buffer)) {
|
|
565
|
-
return false;
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
if ((includesCredentials(this.url) || this.url.port !== null) && this.buffer === "file") {
|
|
569
|
-
return false;
|
|
570
|
-
}
|
|
571
|
-
|
|
572
|
-
if (this.url.scheme === "file" && this.url.host === "") {
|
|
573
|
-
return false;
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
this.url.scheme = this.buffer;
|
|
577
|
-
if (this.stateOverride) {
|
|
578
|
-
if (this.url.port === defaultPort(this.url.scheme)) {
|
|
579
|
-
this.url.port = null;
|
|
580
|
-
}
|
|
581
|
-
return false;
|
|
582
|
-
}
|
|
583
|
-
this.buffer = "";
|
|
584
|
-
if (this.url.scheme === "file") {
|
|
585
|
-
if (this.input[this.pointer + 1] !== p("/") || this.input[this.pointer + 2] !== p("/")) {
|
|
586
|
-
this.parseError = true;
|
|
587
|
-
}
|
|
588
|
-
this.state = "file";
|
|
589
|
-
} else if (isSpecial(this.url) && this.base !== null && this.base.scheme === this.url.scheme) {
|
|
590
|
-
this.state = "special relative or authority";
|
|
591
|
-
} else if (isSpecial(this.url)) {
|
|
592
|
-
this.state = "special authority slashes";
|
|
593
|
-
} else if (this.input[this.pointer + 1] === p("/")) {
|
|
594
|
-
this.state = "path or authority";
|
|
595
|
-
++this.pointer;
|
|
596
|
-
} else {
|
|
597
|
-
this.url.path = "";
|
|
598
|
-
this.state = "opaque path";
|
|
599
|
-
}
|
|
600
|
-
} else if (!this.stateOverride) {
|
|
601
|
-
this.buffer = "";
|
|
602
|
-
this.state = "no scheme";
|
|
603
|
-
this.pointer = -1;
|
|
604
|
-
} else {
|
|
605
|
-
this.parseError = true;
|
|
606
|
-
return failure;
|
|
607
|
-
}
|
|
608
|
-
|
|
609
|
-
return true;
|
|
610
|
-
};
|
|
611
|
-
|
|
612
|
-
URLStateMachine.prototype["parse no scheme"] = function parseNoScheme(c) {
|
|
613
|
-
if (this.base === null || (hasAnOpaquePath(this.base) && c !== p("#"))) {
|
|
614
|
-
return failure;
|
|
615
|
-
} else if (hasAnOpaquePath(this.base) && c === p("#")) {
|
|
616
|
-
this.url.scheme = this.base.scheme;
|
|
617
|
-
this.url.path = this.base.path;
|
|
618
|
-
this.url.query = this.base.query;
|
|
619
|
-
this.url.fragment = "";
|
|
620
|
-
this.state = "fragment";
|
|
621
|
-
} else if (this.base.scheme === "file") {
|
|
622
|
-
this.state = "file";
|
|
623
|
-
--this.pointer;
|
|
624
|
-
} else {
|
|
625
|
-
this.state = "relative";
|
|
626
|
-
--this.pointer;
|
|
627
|
-
}
|
|
628
|
-
|
|
629
|
-
return true;
|
|
630
|
-
};
|
|
631
|
-
|
|
632
|
-
URLStateMachine.prototype["parse special relative or authority"] = function parseSpecialRelativeOrAuthority(c) {
|
|
633
|
-
if (c === p("/") && this.input[this.pointer + 1] === p("/")) {
|
|
634
|
-
this.state = "special authority ignore slashes";
|
|
635
|
-
++this.pointer;
|
|
636
|
-
} else {
|
|
637
|
-
this.parseError = true;
|
|
638
|
-
this.state = "relative";
|
|
639
|
-
--this.pointer;
|
|
640
|
-
}
|
|
641
|
-
|
|
642
|
-
return true;
|
|
643
|
-
};
|
|
644
|
-
|
|
645
|
-
URLStateMachine.prototype["parse path or authority"] = function parsePathOrAuthority(c) {
|
|
646
|
-
if (c === p("/")) {
|
|
647
|
-
this.state = "authority";
|
|
648
|
-
} else {
|
|
649
|
-
this.state = "path";
|
|
650
|
-
--this.pointer;
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
return true;
|
|
654
|
-
};
|
|
655
|
-
|
|
656
|
-
URLStateMachine.prototype["parse relative"] = function parseRelative(c) {
|
|
657
|
-
this.url.scheme = this.base.scheme;
|
|
658
|
-
if (c === p("/")) {
|
|
659
|
-
this.state = "relative slash";
|
|
660
|
-
} else if (isSpecial(this.url) && c === p("\\")) {
|
|
661
|
-
this.parseError = true;
|
|
662
|
-
this.state = "relative slash";
|
|
663
|
-
} else {
|
|
664
|
-
this.url.username = this.base.username;
|
|
665
|
-
this.url.password = this.base.password;
|
|
666
|
-
this.url.host = this.base.host;
|
|
667
|
-
this.url.port = this.base.port;
|
|
668
|
-
this.url.path = this.base.path.slice();
|
|
669
|
-
this.url.query = this.base.query;
|
|
670
|
-
if (c === p("?")) {
|
|
671
|
-
this.url.query = "";
|
|
672
|
-
this.state = "query";
|
|
673
|
-
} else if (c === p("#")) {
|
|
674
|
-
this.url.fragment = "";
|
|
675
|
-
this.state = "fragment";
|
|
676
|
-
} else if (!isNaN(c)) {
|
|
677
|
-
this.url.query = null;
|
|
678
|
-
this.url.path.pop();
|
|
679
|
-
this.state = "path";
|
|
680
|
-
--this.pointer;
|
|
681
|
-
}
|
|
682
|
-
}
|
|
683
|
-
|
|
684
|
-
return true;
|
|
685
|
-
};
|
|
686
|
-
|
|
687
|
-
URLStateMachine.prototype["parse relative slash"] = function parseRelativeSlash(c) {
|
|
688
|
-
if (isSpecial(this.url) && (c === p("/") || c === p("\\"))) {
|
|
689
|
-
if (c === p("\\")) {
|
|
690
|
-
this.parseError = true;
|
|
691
|
-
}
|
|
692
|
-
this.state = "special authority ignore slashes";
|
|
693
|
-
} else if (c === p("/")) {
|
|
694
|
-
this.state = "authority";
|
|
695
|
-
} else {
|
|
696
|
-
this.url.username = this.base.username;
|
|
697
|
-
this.url.password = this.base.password;
|
|
698
|
-
this.url.host = this.base.host;
|
|
699
|
-
this.url.port = this.base.port;
|
|
700
|
-
this.state = "path";
|
|
701
|
-
--this.pointer;
|
|
702
|
-
}
|
|
703
|
-
|
|
704
|
-
return true;
|
|
705
|
-
};
|
|
706
|
-
|
|
707
|
-
URLStateMachine.prototype["parse special authority slashes"] = function parseSpecialAuthoritySlashes(c) {
|
|
708
|
-
if (c === p("/") && this.input[this.pointer + 1] === p("/")) {
|
|
709
|
-
this.state = "special authority ignore slashes";
|
|
710
|
-
++this.pointer;
|
|
711
|
-
} else {
|
|
712
|
-
this.parseError = true;
|
|
713
|
-
this.state = "special authority ignore slashes";
|
|
714
|
-
--this.pointer;
|
|
715
|
-
}
|
|
716
|
-
|
|
717
|
-
return true;
|
|
718
|
-
};
|
|
719
|
-
|
|
720
|
-
URLStateMachine.prototype["parse special authority ignore slashes"] = function parseSpecialAuthorityIgnoreSlashes(c) {
|
|
721
|
-
if (c !== p("/") && c !== p("\\")) {
|
|
722
|
-
this.state = "authority";
|
|
723
|
-
--this.pointer;
|
|
724
|
-
} else {
|
|
725
|
-
this.parseError = true;
|
|
726
|
-
}
|
|
727
|
-
|
|
728
|
-
return true;
|
|
729
|
-
};
|
|
730
|
-
|
|
731
|
-
URLStateMachine.prototype["parse authority"] = function parseAuthority(c, cStr) {
|
|
732
|
-
if (c === p("@")) {
|
|
733
|
-
this.parseError = true;
|
|
734
|
-
if (this.atFlag) {
|
|
735
|
-
this.buffer = `%40${this.buffer}`;
|
|
736
|
-
}
|
|
737
|
-
this.atFlag = true;
|
|
738
|
-
|
|
739
|
-
// careful, this is based on buffer and has its own pointer (this.pointer != pointer) and inner chars
|
|
740
|
-
const len = countSymbols(this.buffer);
|
|
741
|
-
for (let pointer = 0; pointer < len; ++pointer) {
|
|
742
|
-
const codePoint = this.buffer.codePointAt(pointer);
|
|
743
|
-
|
|
744
|
-
if (codePoint === p(":") && !this.passwordTokenSeenFlag) {
|
|
745
|
-
this.passwordTokenSeenFlag = true;
|
|
746
|
-
continue;
|
|
747
|
-
}
|
|
748
|
-
const encodedCodePoints = utf8PercentEncodeCodePoint(codePoint, isUserinfoPercentEncode);
|
|
749
|
-
if (this.passwordTokenSeenFlag) {
|
|
750
|
-
this.url.password += encodedCodePoints;
|
|
751
|
-
} else {
|
|
752
|
-
this.url.username += encodedCodePoints;
|
|
753
|
-
}
|
|
754
|
-
}
|
|
755
|
-
this.buffer = "";
|
|
756
|
-
} else if (isNaN(c) || c === p("/") || c === p("?") || c === p("#") ||
|
|
757
|
-
(isSpecial(this.url) && c === p("\\"))) {
|
|
758
|
-
if (this.atFlag && this.buffer === "") {
|
|
759
|
-
this.parseError = true;
|
|
760
|
-
return failure;
|
|
761
|
-
}
|
|
762
|
-
this.pointer -= countSymbols(this.buffer) + 1;
|
|
763
|
-
this.buffer = "";
|
|
764
|
-
this.state = "host";
|
|
765
|
-
} else {
|
|
766
|
-
this.buffer += cStr;
|
|
767
|
-
}
|
|
768
|
-
|
|
769
|
-
return true;
|
|
770
|
-
};
|
|
771
|
-
|
|
772
|
-
URLStateMachine.prototype["parse hostname"] =
|
|
773
|
-
URLStateMachine.prototype["parse host"] = function parseHostName(c, cStr) {
|
|
774
|
-
if (this.stateOverride && this.url.scheme === "file") {
|
|
775
|
-
--this.pointer;
|
|
776
|
-
this.state = "file host";
|
|
777
|
-
} else if (c === p(":") && !this.arrFlag) {
|
|
778
|
-
if (this.buffer === "") {
|
|
779
|
-
this.parseError = true;
|
|
780
|
-
return failure;
|
|
781
|
-
}
|
|
782
|
-
|
|
783
|
-
if (this.stateOverride === "hostname") {
|
|
784
|
-
return false;
|
|
785
|
-
}
|
|
786
|
-
|
|
787
|
-
const host = parseHost(this.buffer, isNotSpecial(this.url));
|
|
788
|
-
if (host === failure) {
|
|
789
|
-
return failure;
|
|
790
|
-
}
|
|
791
|
-
|
|
792
|
-
this.url.host = host;
|
|
793
|
-
this.buffer = "";
|
|
794
|
-
this.state = "port";
|
|
795
|
-
} else if (isNaN(c) || c === p("/") || c === p("?") || c === p("#") ||
|
|
796
|
-
(isSpecial(this.url) && c === p("\\"))) {
|
|
797
|
-
--this.pointer;
|
|
798
|
-
if (isSpecial(this.url) && this.buffer === "") {
|
|
799
|
-
this.parseError = true;
|
|
800
|
-
return failure;
|
|
801
|
-
} else if (this.stateOverride && this.buffer === "" &&
|
|
802
|
-
(includesCredentials(this.url) || this.url.port !== null)) {
|
|
803
|
-
this.parseError = true;
|
|
804
|
-
return false;
|
|
805
|
-
}
|
|
806
|
-
|
|
807
|
-
const host = parseHost(this.buffer, isNotSpecial(this.url));
|
|
808
|
-
if (host === failure) {
|
|
809
|
-
return failure;
|
|
810
|
-
}
|
|
811
|
-
|
|
812
|
-
this.url.host = host;
|
|
813
|
-
this.buffer = "";
|
|
814
|
-
this.state = "path start";
|
|
815
|
-
if (this.stateOverride) {
|
|
816
|
-
return false;
|
|
817
|
-
}
|
|
818
|
-
} else {
|
|
819
|
-
if (c === p("[")) {
|
|
820
|
-
this.arrFlag = true;
|
|
821
|
-
} else if (c === p("]")) {
|
|
822
|
-
this.arrFlag = false;
|
|
823
|
-
}
|
|
824
|
-
this.buffer += cStr;
|
|
825
|
-
}
|
|
826
|
-
|
|
827
|
-
return true;
|
|
828
|
-
};
|
|
829
|
-
|
|
830
|
-
URLStateMachine.prototype["parse port"] = function parsePort(c, cStr) {
|
|
831
|
-
if (infra.isASCIIDigit(c)) {
|
|
832
|
-
this.buffer += cStr;
|
|
833
|
-
} else if (isNaN(c) || c === p("/") || c === p("?") || c === p("#") ||
|
|
834
|
-
(isSpecial(this.url) && c === p("\\")) ||
|
|
835
|
-
this.stateOverride) {
|
|
836
|
-
if (this.buffer !== "") {
|
|
837
|
-
const port = parseInt(this.buffer);
|
|
838
|
-
if (port > 2 ** 16 - 1) {
|
|
839
|
-
this.parseError = true;
|
|
840
|
-
return failure;
|
|
841
|
-
}
|
|
842
|
-
this.url.port = port === defaultPort(this.url.scheme) ? null : port;
|
|
843
|
-
this.buffer = "";
|
|
844
|
-
}
|
|
845
|
-
if (this.stateOverride) {
|
|
846
|
-
return false;
|
|
847
|
-
}
|
|
848
|
-
this.state = "path start";
|
|
849
|
-
--this.pointer;
|
|
850
|
-
} else {
|
|
851
|
-
this.parseError = true;
|
|
852
|
-
return failure;
|
|
853
|
-
}
|
|
854
|
-
|
|
855
|
-
return true;
|
|
856
|
-
};
|
|
857
|
-
|
|
858
|
-
const fileOtherwiseCodePoints = new Set([p("/"), p("\\"), p("?"), p("#")]);
|
|
859
|
-
|
|
860
|
-
function startsWithWindowsDriveLetter(input, pointer) {
|
|
861
|
-
const length = input.length - pointer;
|
|
862
|
-
return length >= 2 &&
|
|
863
|
-
isWindowsDriveLetterCodePoints(input[pointer], input[pointer + 1]) &&
|
|
864
|
-
(length === 2 || fileOtherwiseCodePoints.has(input[pointer + 2]));
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
URLStateMachine.prototype["parse file"] = function parseFile(c) {
|
|
868
|
-
this.url.scheme = "file";
|
|
869
|
-
this.url.host = "";
|
|
870
|
-
|
|
871
|
-
if (c === p("/") || c === p("\\")) {
|
|
872
|
-
if (c === p("\\")) {
|
|
873
|
-
this.parseError = true;
|
|
874
|
-
}
|
|
875
|
-
this.state = "file slash";
|
|
876
|
-
} else if (this.base !== null && this.base.scheme === "file") {
|
|
877
|
-
this.url.host = this.base.host;
|
|
878
|
-
this.url.path = this.base.path.slice();
|
|
879
|
-
this.url.query = this.base.query;
|
|
880
|
-
if (c === p("?")) {
|
|
881
|
-
this.url.query = "";
|
|
882
|
-
this.state = "query";
|
|
883
|
-
} else if (c === p("#")) {
|
|
884
|
-
this.url.fragment = "";
|
|
885
|
-
this.state = "fragment";
|
|
886
|
-
} else if (!isNaN(c)) {
|
|
887
|
-
this.url.query = null;
|
|
888
|
-
if (!startsWithWindowsDriveLetter(this.input, this.pointer)) {
|
|
889
|
-
shortenPath(this.url);
|
|
890
|
-
} else {
|
|
891
|
-
this.parseError = true;
|
|
892
|
-
this.url.path = [];
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
this.state = "path";
|
|
896
|
-
--this.pointer;
|
|
897
|
-
}
|
|
898
|
-
} else {
|
|
899
|
-
this.state = "path";
|
|
900
|
-
--this.pointer;
|
|
901
|
-
}
|
|
902
|
-
|
|
903
|
-
return true;
|
|
904
|
-
};
|
|
905
|
-
|
|
906
|
-
URLStateMachine.prototype["parse file slash"] = function parseFileSlash(c) {
|
|
907
|
-
if (c === p("/") || c === p("\\")) {
|
|
908
|
-
if (c === p("\\")) {
|
|
909
|
-
this.parseError = true;
|
|
910
|
-
}
|
|
911
|
-
this.state = "file host";
|
|
912
|
-
} else {
|
|
913
|
-
if (this.base !== null && this.base.scheme === "file") {
|
|
914
|
-
if (!startsWithWindowsDriveLetter(this.input, this.pointer) &&
|
|
915
|
-
isNormalizedWindowsDriveLetterString(this.base.path[0])) {
|
|
916
|
-
this.url.path.push(this.base.path[0]);
|
|
917
|
-
}
|
|
918
|
-
this.url.host = this.base.host;
|
|
919
|
-
}
|
|
920
|
-
this.state = "path";
|
|
921
|
-
--this.pointer;
|
|
922
|
-
}
|
|
923
|
-
|
|
924
|
-
return true;
|
|
925
|
-
};
|
|
926
|
-
|
|
927
|
-
URLStateMachine.prototype["parse file host"] = function parseFileHost(c, cStr) {
|
|
928
|
-
if (isNaN(c) || c === p("/") || c === p("\\") || c === p("?") || c === p("#")) {
|
|
929
|
-
--this.pointer;
|
|
930
|
-
if (!this.stateOverride && isWindowsDriveLetterString(this.buffer)) {
|
|
931
|
-
this.parseError = true;
|
|
932
|
-
this.state = "path";
|
|
933
|
-
} else if (this.buffer === "") {
|
|
934
|
-
this.url.host = "";
|
|
935
|
-
if (this.stateOverride) {
|
|
936
|
-
return false;
|
|
937
|
-
}
|
|
938
|
-
this.state = "path start";
|
|
939
|
-
} else {
|
|
940
|
-
let host = parseHost(this.buffer, isNotSpecial(this.url));
|
|
941
|
-
if (host === failure) {
|
|
942
|
-
return failure;
|
|
943
|
-
}
|
|
944
|
-
if (host === "localhost") {
|
|
945
|
-
host = "";
|
|
946
|
-
}
|
|
947
|
-
this.url.host = host;
|
|
948
|
-
|
|
949
|
-
if (this.stateOverride) {
|
|
950
|
-
return false;
|
|
951
|
-
}
|
|
952
|
-
|
|
953
|
-
this.buffer = "";
|
|
954
|
-
this.state = "path start";
|
|
955
|
-
}
|
|
956
|
-
} else {
|
|
957
|
-
this.buffer += cStr;
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
return true;
|
|
961
|
-
};
|
|
962
|
-
|
|
963
|
-
URLStateMachine.prototype["parse path start"] = function parsePathStart(c) {
|
|
964
|
-
if (isSpecial(this.url)) {
|
|
965
|
-
if (c === p("\\")) {
|
|
966
|
-
this.parseError = true;
|
|
967
|
-
}
|
|
968
|
-
this.state = "path";
|
|
969
|
-
|
|
970
|
-
if (c !== p("/") && c !== p("\\")) {
|
|
971
|
-
--this.pointer;
|
|
972
|
-
}
|
|
973
|
-
} else if (!this.stateOverride && c === p("?")) {
|
|
974
|
-
this.url.query = "";
|
|
975
|
-
this.state = "query";
|
|
976
|
-
} else if (!this.stateOverride && c === p("#")) {
|
|
977
|
-
this.url.fragment = "";
|
|
978
|
-
this.state = "fragment";
|
|
979
|
-
} else if (c !== undefined) {
|
|
980
|
-
this.state = "path";
|
|
981
|
-
if (c !== p("/")) {
|
|
982
|
-
--this.pointer;
|
|
983
|
-
}
|
|
984
|
-
} else if (this.stateOverride && this.url.host === null) {
|
|
985
|
-
this.url.path.push("");
|
|
986
|
-
}
|
|
987
|
-
|
|
988
|
-
return true;
|
|
989
|
-
};
|
|
990
|
-
|
|
991
|
-
URLStateMachine.prototype["parse path"] = function parsePath(c) {
|
|
992
|
-
if (isNaN(c) || c === p("/") || (isSpecial(this.url) && c === p("\\")) ||
|
|
993
|
-
(!this.stateOverride && (c === p("?") || c === p("#")))) {
|
|
994
|
-
if (isSpecial(this.url) && c === p("\\")) {
|
|
995
|
-
this.parseError = true;
|
|
996
|
-
}
|
|
997
|
-
|
|
998
|
-
if (isDoubleDot(this.buffer)) {
|
|
999
|
-
shortenPath(this.url);
|
|
1000
|
-
if (c !== p("/") && !(isSpecial(this.url) && c === p("\\"))) {
|
|
1001
|
-
this.url.path.push("");
|
|
1002
|
-
}
|
|
1003
|
-
} else if (isSingleDot(this.buffer) && c !== p("/") &&
|
|
1004
|
-
!(isSpecial(this.url) && c === p("\\"))) {
|
|
1005
|
-
this.url.path.push("");
|
|
1006
|
-
} else if (!isSingleDot(this.buffer)) {
|
|
1007
|
-
if (this.url.scheme === "file" && this.url.path.length === 0 && isWindowsDriveLetterString(this.buffer)) {
|
|
1008
|
-
this.buffer = `${this.buffer[0]}:`;
|
|
1009
|
-
}
|
|
1010
|
-
this.url.path.push(this.buffer);
|
|
1011
|
-
}
|
|
1012
|
-
this.buffer = "";
|
|
1013
|
-
if (c === p("?")) {
|
|
1014
|
-
this.url.query = "";
|
|
1015
|
-
this.state = "query";
|
|
1016
|
-
}
|
|
1017
|
-
if (c === p("#")) {
|
|
1018
|
-
this.url.fragment = "";
|
|
1019
|
-
this.state = "fragment";
|
|
1020
|
-
}
|
|
1021
|
-
} else {
|
|
1022
|
-
// TODO: If c is not a URL code point and not "%", parse error.
|
|
1023
|
-
|
|
1024
|
-
if (c === p("%") &&
|
|
1025
|
-
(!infra.isASCIIHex(this.input[this.pointer + 1]) ||
|
|
1026
|
-
!infra.isASCIIHex(this.input[this.pointer + 2]))) {
|
|
1027
|
-
this.parseError = true;
|
|
1028
|
-
}
|
|
1029
|
-
|
|
1030
|
-
this.buffer += utf8PercentEncodeCodePoint(c, isPathPercentEncode);
|
|
1031
|
-
}
|
|
1032
|
-
|
|
1033
|
-
return true;
|
|
1034
|
-
};
|
|
1035
|
-
|
|
1036
|
-
URLStateMachine.prototype["parse opaque path"] = function parseOpaquePath(c) {
|
|
1037
|
-
if (c === p("?")) {
|
|
1038
|
-
this.url.query = "";
|
|
1039
|
-
this.state = "query";
|
|
1040
|
-
} else if (c === p("#")) {
|
|
1041
|
-
this.url.fragment = "";
|
|
1042
|
-
this.state = "fragment";
|
|
1043
|
-
} else {
|
|
1044
|
-
// TODO: Add: not a URL code point
|
|
1045
|
-
if (!isNaN(c) && c !== p("%")) {
|
|
1046
|
-
this.parseError = true;
|
|
1047
|
-
}
|
|
1048
|
-
|
|
1049
|
-
if (c === p("%") &&
|
|
1050
|
-
(!infra.isASCIIHex(this.input[this.pointer + 1]) ||
|
|
1051
|
-
!infra.isASCIIHex(this.input[this.pointer + 2]))) {
|
|
1052
|
-
this.parseError = true;
|
|
1053
|
-
}
|
|
1054
|
-
|
|
1055
|
-
if (!isNaN(c)) {
|
|
1056
|
-
this.url.path += utf8PercentEncodeCodePoint(c, isC0ControlPercentEncode);
|
|
1057
|
-
}
|
|
1058
|
-
}
|
|
1059
|
-
|
|
1060
|
-
return true;
|
|
1061
|
-
};
|
|
1062
|
-
|
|
1063
|
-
URLStateMachine.prototype["parse query"] = function parseQuery(c, cStr) {
|
|
1064
|
-
if (!isSpecial(this.url) || this.url.scheme === "ws" || this.url.scheme === "wss") {
|
|
1065
|
-
this.encodingOverride = "utf-8";
|
|
1066
|
-
}
|
|
1067
|
-
|
|
1068
|
-
if ((!this.stateOverride && c === p("#")) || isNaN(c)) {
|
|
1069
|
-
const queryPercentEncodePredicate = isSpecial(this.url) ? isSpecialQueryPercentEncode : isQueryPercentEncode;
|
|
1070
|
-
this.url.query += utf8PercentEncodeString(this.buffer, queryPercentEncodePredicate);
|
|
1071
|
-
|
|
1072
|
-
this.buffer = "";
|
|
1073
|
-
|
|
1074
|
-
if (c === p("#")) {
|
|
1075
|
-
this.url.fragment = "";
|
|
1076
|
-
this.state = "fragment";
|
|
1077
|
-
}
|
|
1078
|
-
} else if (!isNaN(c)) {
|
|
1079
|
-
// TODO: If c is not a URL code point and not "%", parse error.
|
|
1080
|
-
|
|
1081
|
-
if (c === p("%") &&
|
|
1082
|
-
(!infra.isASCIIHex(this.input[this.pointer + 1]) ||
|
|
1083
|
-
!infra.isASCIIHex(this.input[this.pointer + 2]))) {
|
|
1084
|
-
this.parseError = true;
|
|
1085
|
-
}
|
|
1086
|
-
|
|
1087
|
-
this.buffer += cStr;
|
|
1088
|
-
}
|
|
1089
|
-
|
|
1090
|
-
return true;
|
|
1091
|
-
};
|
|
1092
|
-
|
|
1093
|
-
URLStateMachine.prototype["parse fragment"] = function parseFragment(c) {
|
|
1094
|
-
if (!isNaN(c)) {
|
|
1095
|
-
// TODO: If c is not a URL code point and not "%", parse error.
|
|
1096
|
-
if (c === p("%") &&
|
|
1097
|
-
(!infra.isASCIIHex(this.input[this.pointer + 1]) ||
|
|
1098
|
-
!infra.isASCIIHex(this.input[this.pointer + 2]))) {
|
|
1099
|
-
this.parseError = true;
|
|
1100
|
-
}
|
|
1101
|
-
|
|
1102
|
-
this.url.fragment += utf8PercentEncodeCodePoint(c, isFragmentPercentEncode);
|
|
1103
|
-
}
|
|
1104
|
-
|
|
1105
|
-
return true;
|
|
1106
|
-
};
|
|
1107
|
-
|
|
1108
|
-
function serializeURL(url, excludeFragment) {
|
|
1109
|
-
let output = `${url.scheme}:`;
|
|
1110
|
-
if (url.host !== null) {
|
|
1111
|
-
output += "//";
|
|
1112
|
-
|
|
1113
|
-
if (url.username !== "" || url.password !== "") {
|
|
1114
|
-
output += url.username;
|
|
1115
|
-
if (url.password !== "") {
|
|
1116
|
-
output += `:${url.password}`;
|
|
1117
|
-
}
|
|
1118
|
-
output += "@";
|
|
1119
|
-
}
|
|
1120
|
-
|
|
1121
|
-
output += serializeHost(url.host);
|
|
1122
|
-
|
|
1123
|
-
if (url.port !== null) {
|
|
1124
|
-
output += `:${url.port}`;
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
|
|
1128
|
-
if (url.host === null && !hasAnOpaquePath(url) && url.path.length > 1 && url.path[0] === "") {
|
|
1129
|
-
output += "/.";
|
|
1130
|
-
}
|
|
1131
|
-
output += serializePath(url);
|
|
1132
|
-
|
|
1133
|
-
if (url.query !== null) {
|
|
1134
|
-
output += `?${url.query}`;
|
|
1135
|
-
}
|
|
1136
|
-
|
|
1137
|
-
if (!excludeFragment && url.fragment !== null) {
|
|
1138
|
-
output += `#${url.fragment}`;
|
|
1139
|
-
}
|
|
1140
|
-
|
|
1141
|
-
return output;
|
|
1142
|
-
}
|
|
1143
|
-
|
|
1144
|
-
function serializeOrigin(tuple) {
|
|
1145
|
-
let result = `${tuple.scheme}://`;
|
|
1146
|
-
result += serializeHost(tuple.host);
|
|
1147
|
-
|
|
1148
|
-
if (tuple.port !== null) {
|
|
1149
|
-
result += `:${tuple.port}`;
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
return result;
|
|
1153
|
-
}
|
|
1154
|
-
|
|
1155
|
-
function serializePath(url) {
|
|
1156
|
-
if (hasAnOpaquePath(url)) {
|
|
1157
|
-
return url.path;
|
|
1158
|
-
}
|
|
1159
|
-
|
|
1160
|
-
let output = "";
|
|
1161
|
-
for (const segment of url.path) {
|
|
1162
|
-
output += `/${segment}`;
|
|
1163
|
-
}
|
|
1164
|
-
return output;
|
|
1165
|
-
}
|
|
1166
|
-
|
|
1167
|
-
module.exports.serializeURL = serializeURL;
|
|
1168
|
-
|
|
1169
|
-
module.exports.serializePath = serializePath;
|
|
1170
|
-
|
|
1171
|
-
module.exports.serializeURLOrigin = function (url) {
|
|
1172
|
-
// https://url.spec.whatwg.org/#concept-url-origin
|
|
1173
|
-
switch (url.scheme) {
|
|
1174
|
-
case "blob":
|
|
1175
|
-
try {
|
|
1176
|
-
return module.exports.serializeURLOrigin(module.exports.parseURL(serializePath(url)));
|
|
1177
|
-
} catch (e) {
|
|
1178
|
-
// serializing an opaque origin returns "null"
|
|
1179
|
-
return "null";
|
|
1180
|
-
}
|
|
1181
|
-
case "ftp":
|
|
1182
|
-
case "http":
|
|
1183
|
-
case "https":
|
|
1184
|
-
case "ws":
|
|
1185
|
-
case "wss":
|
|
1186
|
-
return serializeOrigin({
|
|
1187
|
-
scheme: url.scheme,
|
|
1188
|
-
host: url.host,
|
|
1189
|
-
port: url.port
|
|
1190
|
-
});
|
|
1191
|
-
case "file":
|
|
1192
|
-
// The spec says:
|
|
1193
|
-
// > Unfortunate as it is, this is left as an exercise to the reader. When in doubt, return a new opaque origin.
|
|
1194
|
-
// Browsers tested so far:
|
|
1195
|
-
// - Chrome says "file://", but treats file: URLs as cross-origin for most (all?) purposes; see e.g.
|
|
1196
|
-
// https://bugs.chromium.org/p/chromium/issues/detail?id=37586
|
|
1197
|
-
// - Firefox says "null", but treats file: URLs as same-origin sometimes based on directory stuff; see
|
|
1198
|
-
// https://developer.mozilla.org/en-US/docs/Archive/Misc_top_level/Same-origin_policy_for_file:_URIs
|
|
1199
|
-
return "null";
|
|
1200
|
-
default:
|
|
1201
|
-
// serializing an opaque origin returns "null"
|
|
1202
|
-
return "null";
|
|
1203
|
-
}
|
|
1204
|
-
};
|
|
1205
|
-
|
|
1206
|
-
module.exports.basicURLParse = function (input, options) {
|
|
1207
|
-
if (options === undefined) {
|
|
1208
|
-
options = {};
|
|
1209
|
-
}
|
|
1210
|
-
|
|
1211
|
-
const usm = new URLStateMachine(input, options.baseURL, options.encodingOverride, options.url, options.stateOverride);
|
|
1212
|
-
if (usm.failure) {
|
|
1213
|
-
return null;
|
|
1214
|
-
}
|
|
1215
|
-
|
|
1216
|
-
return usm.url;
|
|
1217
|
-
};
|
|
1218
|
-
|
|
1219
|
-
module.exports.setTheUsername = function (url, username) {
|
|
1220
|
-
url.username = utf8PercentEncodeString(username, isUserinfoPercentEncode);
|
|
1221
|
-
};
|
|
1222
|
-
|
|
1223
|
-
module.exports.setThePassword = function (url, password) {
|
|
1224
|
-
url.password = utf8PercentEncodeString(password, isUserinfoPercentEncode);
|
|
1225
|
-
};
|
|
1226
|
-
|
|
1227
|
-
module.exports.serializeHost = serializeHost;
|
|
1228
|
-
|
|
1229
|
-
module.exports.cannotHaveAUsernamePasswordPort = cannotHaveAUsernamePasswordPort;
|
|
1230
|
-
|
|
1231
|
-
module.exports.hasAnOpaquePath = hasAnOpaquePath;
|
|
1232
|
-
|
|
1233
|
-
module.exports.serializeInteger = function (integer) {
|
|
1234
|
-
return String(integer);
|
|
1235
|
-
};
|
|
1236
|
-
|
|
1237
|
-
module.exports.parseURL = function (input, options) {
|
|
1238
|
-
if (options === undefined) {
|
|
1239
|
-
options = {};
|
|
1240
|
-
}
|
|
1241
|
-
|
|
1242
|
-
// We don't handle blobs, so this just delegates:
|
|
1243
|
-
return module.exports.basicURLParse(input, { baseURL: options.baseURL, encodingOverride: options.encodingOverride });
|
|
1244
|
-
};
|