@depup/whatwg-url 16.0.1-depup.0
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/LICENSE.txt +21 -0
- package/README.md +31 -0
- package/changes.json +10 -0
- package/index.js +27 -0
- package/lib/Function.js +42 -0
- package/lib/URL-impl.js +234 -0
- package/lib/URL.js +499 -0
- package/lib/URLSearchParams-impl.js +135 -0
- package/lib/URLSearchParams.js +505 -0
- package/lib/VoidFunction.js +26 -0
- package/lib/encoding.js +16 -0
- package/lib/infra.js +26 -0
- package/lib/percent-encoding.js +147 -0
- package/lib/url-state-machine.js +1284 -0
- package/lib/urlencoded.js +89 -0
- package/lib/utils.js +252 -0
- package/package.json +77 -0
- package/webidl2js-wrapper.js +7 -0
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const { utf8Encode, utf8DecodeWithoutBOM } = require("./encoding");
|
|
3
|
+
const { percentDecodeBytes, utf8PercentEncodeString, isURLEncodedPercentEncode } = require("./percent-encoding");
|
|
4
|
+
|
|
5
|
+
function p(char) {
|
|
6
|
+
return char.codePointAt(0);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
// https://url.spec.whatwg.org/#concept-urlencoded-parser
|
|
10
|
+
function parseUrlencoded(input) {
|
|
11
|
+
const sequences = strictlySplitByteSequence(input, p("&"));
|
|
12
|
+
const output = [];
|
|
13
|
+
for (const bytes of sequences) {
|
|
14
|
+
if (bytes.length === 0) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let name, value;
|
|
19
|
+
const indexOfEqual = bytes.indexOf(p("="));
|
|
20
|
+
|
|
21
|
+
if (indexOfEqual >= 0) {
|
|
22
|
+
name = bytes.slice(0, indexOfEqual);
|
|
23
|
+
value = bytes.slice(indexOfEqual + 1);
|
|
24
|
+
} else {
|
|
25
|
+
name = bytes;
|
|
26
|
+
value = new Uint8Array(0);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
name = replaceByteInByteSequence(name, 0x2B, 0x20);
|
|
30
|
+
value = replaceByteInByteSequence(value, 0x2B, 0x20);
|
|
31
|
+
|
|
32
|
+
const nameString = utf8DecodeWithoutBOM(percentDecodeBytes(name));
|
|
33
|
+
const valueString = utf8DecodeWithoutBOM(percentDecodeBytes(value));
|
|
34
|
+
|
|
35
|
+
output.push([nameString, valueString]);
|
|
36
|
+
}
|
|
37
|
+
return output;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// https://url.spec.whatwg.org/#concept-urlencoded-string-parser
|
|
41
|
+
function parseUrlencodedString(input) {
|
|
42
|
+
return parseUrlencoded(utf8Encode(input));
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// https://url.spec.whatwg.org/#concept-urlencoded-serializer
|
|
46
|
+
function serializeUrlencoded(tuples) {
|
|
47
|
+
// TODO: accept and use encoding argument
|
|
48
|
+
|
|
49
|
+
let output = "";
|
|
50
|
+
for (const [i, tuple] of tuples.entries()) {
|
|
51
|
+
const name = utf8PercentEncodeString(tuple[0], isURLEncodedPercentEncode, true);
|
|
52
|
+
const value = utf8PercentEncodeString(tuple[1], isURLEncodedPercentEncode, true);
|
|
53
|
+
|
|
54
|
+
if (i !== 0) {
|
|
55
|
+
output += "&";
|
|
56
|
+
}
|
|
57
|
+
output += `${name}=${value}`;
|
|
58
|
+
}
|
|
59
|
+
return output;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function strictlySplitByteSequence(buf, cp) {
|
|
63
|
+
const list = [];
|
|
64
|
+
let last = 0;
|
|
65
|
+
let i = buf.indexOf(cp);
|
|
66
|
+
while (i >= 0) {
|
|
67
|
+
list.push(buf.slice(last, i));
|
|
68
|
+
last = i + 1;
|
|
69
|
+
i = buf.indexOf(cp, last);
|
|
70
|
+
}
|
|
71
|
+
if (last !== buf.length) {
|
|
72
|
+
list.push(buf.slice(last));
|
|
73
|
+
}
|
|
74
|
+
return list;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function replaceByteInByteSequence(buf, from, to) {
|
|
78
|
+
let i = buf.indexOf(from);
|
|
79
|
+
while (i >= 0) {
|
|
80
|
+
buf[i] = to;
|
|
81
|
+
i = buf.indexOf(from, i + 1);
|
|
82
|
+
}
|
|
83
|
+
return buf;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
module.exports = {
|
|
87
|
+
parseUrlencodedString,
|
|
88
|
+
serializeUrlencoded
|
|
89
|
+
};
|
package/lib/utils.js
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
// Returns "Type(value) is Object" in ES terminology.
|
|
4
|
+
function isObject(value) {
|
|
5
|
+
return (typeof value === "object" && value !== null) || typeof value === "function";
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
const call = Function.call.bind(Function.call);
|
|
9
|
+
|
|
10
|
+
// Like `Object.assign`, but using `[[GetOwnProperty]]` and `[[DefineOwnProperty]]`
|
|
11
|
+
// instead of `[[Get]]` and `[[Set]]` and only allowing objects
|
|
12
|
+
function define(target, source) {
|
|
13
|
+
for (const key of Reflect.ownKeys(source)) {
|
|
14
|
+
const descriptor = Reflect.getOwnPropertyDescriptor(source, key);
|
|
15
|
+
if (descriptor && !Reflect.defineProperty(target, key, descriptor)) {
|
|
16
|
+
throw new TypeError(`Cannot redefine property: ${String(key)}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function newObjectInRealm(globalObject, object) {
|
|
22
|
+
const ctorRegistry = initCtorRegistry(globalObject);
|
|
23
|
+
return Object.defineProperties(
|
|
24
|
+
Object.create(ctorRegistry["%Object.prototype%"]),
|
|
25
|
+
Object.getOwnPropertyDescriptors(object)
|
|
26
|
+
);
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const wrapperSymbol = Symbol("wrapper");
|
|
30
|
+
const implSymbol = Symbol("impl");
|
|
31
|
+
const sameObjectCaches = Symbol("SameObject caches");
|
|
32
|
+
const ctorRegistrySymbol = Symbol.for("[webidl2js] constructor registry");
|
|
33
|
+
|
|
34
|
+
const AsyncIteratorPrototype = Object.getPrototypeOf(Object.getPrototypeOf(async function* () {}).prototype);
|
|
35
|
+
|
|
36
|
+
function initCtorRegistry(globalObject) {
|
|
37
|
+
if (Object.hasOwn(globalObject, ctorRegistrySymbol)) {
|
|
38
|
+
return globalObject[ctorRegistrySymbol];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const ctorRegistry = Object.create(null);
|
|
42
|
+
|
|
43
|
+
// In addition to registering all the WebIDL2JS-generated types in the constructor registry,
|
|
44
|
+
// we also register a few intrinsics that we make use of in generated code, since they are not
|
|
45
|
+
// easy to grab from the globalObject variable.
|
|
46
|
+
ctorRegistry["%Object.prototype%"] = globalObject.Object.prototype;
|
|
47
|
+
ctorRegistry["%IteratorPrototype%"] = Object.getPrototypeOf(
|
|
48
|
+
Object.getPrototypeOf(new globalObject.Array()[Symbol.iterator]())
|
|
49
|
+
);
|
|
50
|
+
|
|
51
|
+
try {
|
|
52
|
+
ctorRegistry["%AsyncIteratorPrototype%"] = Object.getPrototypeOf(
|
|
53
|
+
Object.getPrototypeOf(
|
|
54
|
+
globalObject.eval("(async function* () {})").prototype
|
|
55
|
+
)
|
|
56
|
+
);
|
|
57
|
+
} catch {
|
|
58
|
+
ctorRegistry["%AsyncIteratorPrototype%"] = AsyncIteratorPrototype;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
globalObject[ctorRegistrySymbol] = ctorRegistry;
|
|
62
|
+
return ctorRegistry;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
function getSameObject(wrapper, prop, creator) {
|
|
66
|
+
if (!wrapper[sameObjectCaches]) {
|
|
67
|
+
wrapper[sameObjectCaches] = Object.create(null);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (prop in wrapper[sameObjectCaches]) {
|
|
71
|
+
return wrapper[sameObjectCaches][prop];
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
wrapper[sameObjectCaches][prop] = creator();
|
|
75
|
+
return wrapper[sameObjectCaches][prop];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
function wrapperForImpl(impl) {
|
|
79
|
+
return impl ? impl[wrapperSymbol] : null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function implForWrapper(wrapper) {
|
|
83
|
+
return wrapper ? wrapper[implSymbol] : null;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function tryWrapperForImpl(impl) {
|
|
87
|
+
const wrapper = wrapperForImpl(impl);
|
|
88
|
+
return wrapper ? wrapper : impl;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function tryImplForWrapper(wrapper) {
|
|
92
|
+
const impl = implForWrapper(wrapper);
|
|
93
|
+
return impl ? impl : wrapper;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
const iterInternalSymbol = Symbol("internal");
|
|
97
|
+
|
|
98
|
+
function isArrayIndexPropName(P) {
|
|
99
|
+
if (typeof P !== "string") {
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
102
|
+
const i = P >>> 0;
|
|
103
|
+
if (i === 2 ** 32 - 1) {
|
|
104
|
+
return false;
|
|
105
|
+
}
|
|
106
|
+
const s = `${i}`;
|
|
107
|
+
if (P !== s) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const arrayBufferByteLengthGetter =
|
|
114
|
+
Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, "byteLength").get;
|
|
115
|
+
function isArrayBuffer(value) {
|
|
116
|
+
try {
|
|
117
|
+
arrayBufferByteLengthGetter.call(value);
|
|
118
|
+
return true;
|
|
119
|
+
} catch {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const sharedArrayBufferByteLengthGetter =
|
|
125
|
+
Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, "byteLength").get;
|
|
126
|
+
function isSharedArrayBuffer(value) {
|
|
127
|
+
try {
|
|
128
|
+
sharedArrayBufferByteLengthGetter.call(value);
|
|
129
|
+
return true;
|
|
130
|
+
} catch {
|
|
131
|
+
return false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function iteratorResult([key, value], kind) {
|
|
136
|
+
let result;
|
|
137
|
+
switch (kind) {
|
|
138
|
+
case "key":
|
|
139
|
+
result = key;
|
|
140
|
+
break;
|
|
141
|
+
case "value":
|
|
142
|
+
result = value;
|
|
143
|
+
break;
|
|
144
|
+
case "key+value":
|
|
145
|
+
result = [key, value];
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
return { value: result, done: false };
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function ordinarySetWithOwnDescriptor(target, property, value, receiver, ownDesc) {
|
|
152
|
+
if (ownDesc === undefined) {
|
|
153
|
+
const parent = Reflect.getPrototypeOf(target);
|
|
154
|
+
if (parent !== null) {
|
|
155
|
+
return Reflect.set(parent, property, value, receiver);
|
|
156
|
+
}
|
|
157
|
+
ownDesc = { writable: true, enumerable: true, configurable: true, value: undefined };
|
|
158
|
+
}
|
|
159
|
+
if (isDataDescriptor(ownDesc)) {
|
|
160
|
+
if (!ownDesc.writable) {
|
|
161
|
+
return false;
|
|
162
|
+
}
|
|
163
|
+
if (!isObject(receiver)) {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
const existingDesc = Reflect.getOwnPropertyDescriptor(receiver, property);
|
|
167
|
+
if (existingDesc !== undefined) {
|
|
168
|
+
if (isAccessorDescriptor(existingDesc)) {
|
|
169
|
+
return false;
|
|
170
|
+
}
|
|
171
|
+
if (existingDesc.writable === false) {
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
const valueDesc = { value };
|
|
175
|
+
return Reflect.defineProperty(receiver, property, valueDesc);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return Reflect.defineProperty(
|
|
179
|
+
receiver,
|
|
180
|
+
property,
|
|
181
|
+
{ value, writable: true, enumerable: true, configurable: true }
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
const setter = ownDesc.set;
|
|
186
|
+
if (setter === undefined) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
call(setter, receiver, value);
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
function isDataDescriptor(desc) {
|
|
194
|
+
return Object.hasOwn(desc, "value") || Object.hasOwn(desc, "writable");
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
function isAccessorDescriptor(desc) {
|
|
198
|
+
return Object.hasOwn(desc, "get") || Object.hasOwn(desc, "set");
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
const supportsPropertyIndex = Symbol("supports property index");
|
|
202
|
+
const supportedPropertyIndices = Symbol("supported property indices");
|
|
203
|
+
const supportsPropertyName = Symbol("supports property name");
|
|
204
|
+
const supportedPropertyNames = Symbol("supported property names");
|
|
205
|
+
const indexedGet = Symbol("indexed property get");
|
|
206
|
+
const indexedSetNew = Symbol("indexed property set new");
|
|
207
|
+
const indexedSetExisting = Symbol("indexed property set existing");
|
|
208
|
+
const namedGet = Symbol("named property get");
|
|
209
|
+
const namedSetNew = Symbol("named property set new");
|
|
210
|
+
const namedSetExisting = Symbol("named property set existing");
|
|
211
|
+
const namedDelete = Symbol("named property delete");
|
|
212
|
+
|
|
213
|
+
const asyncIteratorNext = Symbol("async iterator get the next iteration result");
|
|
214
|
+
const asyncIteratorReturn = Symbol("async iterator return steps");
|
|
215
|
+
const asyncIteratorInit = Symbol("async iterator initialization steps");
|
|
216
|
+
const asyncIteratorEOI = Symbol("async iterator end of iteration");
|
|
217
|
+
|
|
218
|
+
module.exports = exports = {
|
|
219
|
+
isObject,
|
|
220
|
+
define,
|
|
221
|
+
newObjectInRealm,
|
|
222
|
+
wrapperSymbol,
|
|
223
|
+
implSymbol,
|
|
224
|
+
getSameObject,
|
|
225
|
+
ctorRegistrySymbol,
|
|
226
|
+
initCtorRegistry,
|
|
227
|
+
wrapperForImpl,
|
|
228
|
+
implForWrapper,
|
|
229
|
+
tryWrapperForImpl,
|
|
230
|
+
tryImplForWrapper,
|
|
231
|
+
iterInternalSymbol,
|
|
232
|
+
isArrayBuffer,
|
|
233
|
+
isSharedArrayBuffer,
|
|
234
|
+
isArrayIndexPropName,
|
|
235
|
+
supportsPropertyIndex,
|
|
236
|
+
supportedPropertyIndices,
|
|
237
|
+
supportsPropertyName,
|
|
238
|
+
supportedPropertyNames,
|
|
239
|
+
indexedGet,
|
|
240
|
+
indexedSetNew,
|
|
241
|
+
indexedSetExisting,
|
|
242
|
+
namedGet,
|
|
243
|
+
namedSetNew,
|
|
244
|
+
namedSetExisting,
|
|
245
|
+
namedDelete,
|
|
246
|
+
asyncIteratorNext,
|
|
247
|
+
asyncIteratorReturn,
|
|
248
|
+
asyncIteratorInit,
|
|
249
|
+
asyncIteratorEOI,
|
|
250
|
+
iteratorResult,
|
|
251
|
+
ordinarySetWithOwnDescriptor
|
|
252
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@depup/whatwg-url",
|
|
3
|
+
"version": "16.0.1-depup.0",
|
|
4
|
+
"description": "[DepUp] An implementation of the WHATWG URL Standard's URL API and parsing machinery",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"files": [
|
|
7
|
+
"index.js",
|
|
8
|
+
"webidl2js-wrapper.js",
|
|
9
|
+
"lib/*.js",
|
|
10
|
+
"changes.json",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
13
|
+
"author": "Sebastian Mayr <github@smayr.name>",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"repository": {
|
|
16
|
+
"type": "git",
|
|
17
|
+
"url": "git+https://github.com/jsdom/whatwg-url.git"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"@exodus/bytes": "^1.15.0",
|
|
21
|
+
"tr46": "^6.0.0",
|
|
22
|
+
"webidl-conversions": "^8.0.1"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@domenic/eslint-config": "^4.1.0",
|
|
26
|
+
"tinybench": "^6.0.0",
|
|
27
|
+
"c8": "^10.1.3",
|
|
28
|
+
"esbuild": "^0.27.2",
|
|
29
|
+
"eslint": "^9.39.2",
|
|
30
|
+
"globals": "^17.3.0",
|
|
31
|
+
"webidl2js": "^19.1.0"
|
|
32
|
+
},
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": "^20.19.0 || ^22.12.0 || >=24.0.0"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"coverage": "c8 node --test --experimental-test-coverage test/*.js",
|
|
38
|
+
"lint": "eslint",
|
|
39
|
+
"pretest": "node scripts/get-latest-platform-tests.js && node scripts/transform.js",
|
|
40
|
+
"build-live-viewer": "esbuild --bundle --format=esm --sourcemap --outfile=live-viewer/whatwg-url.mjs index.js",
|
|
41
|
+
"test": "node --test test/*.js",
|
|
42
|
+
"bench": "node scripts/benchmark.js"
|
|
43
|
+
},
|
|
44
|
+
"c8": {
|
|
45
|
+
"reporter": [
|
|
46
|
+
"text",
|
|
47
|
+
"html"
|
|
48
|
+
],
|
|
49
|
+
"exclude": [
|
|
50
|
+
"lib/Function.js",
|
|
51
|
+
"lib/URL.js",
|
|
52
|
+
"lib/URLSearchParams.js",
|
|
53
|
+
"lib/utils.js",
|
|
54
|
+
"scripts/",
|
|
55
|
+
"test/"
|
|
56
|
+
]
|
|
57
|
+
},
|
|
58
|
+
"keywords": [
|
|
59
|
+
"depup",
|
|
60
|
+
"dependency-bumped",
|
|
61
|
+
"updated-deps",
|
|
62
|
+
"whatwg-url"
|
|
63
|
+
],
|
|
64
|
+
"depup": {
|
|
65
|
+
"changes": {
|
|
66
|
+
"@exodus/bytes": {
|
|
67
|
+
"from": "^1.11.0",
|
|
68
|
+
"to": "^1.15.0"
|
|
69
|
+
}
|
|
70
|
+
},
|
|
71
|
+
"depsUpdated": 1,
|
|
72
|
+
"originalPackage": "whatwg-url",
|
|
73
|
+
"originalVersion": "16.0.1",
|
|
74
|
+
"processedAt": "2026-03-17T16:39:38.659Z",
|
|
75
|
+
"smokeTest": "passed"
|
|
76
|
+
}
|
|
77
|
+
}
|