whatwg-url 4.8.0 → 5.0.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/README.md +2 -2
- package/lib/URL-impl.js +1 -1
- package/lib/public-api.js +1 -1
- package/lib/url-state-machine.js +40 -45
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@ whatwg-url is a full implementation of the WHATWG [URL Standard](https://url.spe
|
|
|
4
4
|
|
|
5
5
|
## Current Status
|
|
6
6
|
|
|
7
|
-
whatwg-url is currently up to date with the URL spec up to commit [
|
|
7
|
+
whatwg-url is currently up to date with the URL spec up to commit [a62223](https://github.com/whatwg/url/commit/a622235308342c9adc7fc2fd1659ff059f7d5e2a).
|
|
8
8
|
|
|
9
9
|
## API
|
|
10
10
|
|
|
@@ -21,7 +21,7 @@ The following methods are exported for use by places like jsdom that need to imp
|
|
|
21
21
|
- [URL serializer](https://url.spec.whatwg.org/#concept-url-serializer): `serializeURL(urlRecord, excludeFragment)`
|
|
22
22
|
- [Host serializer](https://url.spec.whatwg.org/#concept-host-serializer): `serializeHost(hostFromURLRecord)`
|
|
23
23
|
- [Serialize an integer](https://url.spec.whatwg.org/#serialize-an-integer): `serializeInteger(number)`
|
|
24
|
-
- [Origin](https://url.spec.whatwg.org/#concept-url-origin) [
|
|
24
|
+
- [Origin](https://url.spec.whatwg.org/#concept-url-origin) [serializer](https://html.spec.whatwg.org/multipage/browsers.html#serialization-of-an-origin): `serializeURLOrigin(urlRecord)`
|
|
25
25
|
- [Set the username](https://url.spec.whatwg.org/#set-the-username): `setTheUsername(urlRecord, usernameString)`
|
|
26
26
|
- [Set the password](https://url.spec.whatwg.org/#set-the-password): `setThePassword(urlRecord, passwordString)`
|
|
27
27
|
- [Cannot have a username/password/port](https://url.spec.whatwg.org/#cannot-have-a-username-password-port): `cannotHaveAUsernamePasswordPort(urlRecord)`
|
package/lib/URL-impl.js
CHANGED
package/lib/public-api.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
exports.URL = require("./URL").interface;
|
|
4
4
|
exports.serializeURL = require("./url-state-machine").serializeURL;
|
|
5
|
-
exports.
|
|
5
|
+
exports.serializeURLOrigin = require("./url-state-machine").serializeURLOrigin;
|
|
6
6
|
exports.basicURLParse = require("./url-state-machine").basicURLParse;
|
|
7
7
|
exports.setTheUsername = require("./url-state-machine").setTheUsername;
|
|
8
8
|
exports.setThePassword = require("./url-state-machine").setThePassword;
|
package/lib/url-state-machine.js
CHANGED
|
@@ -214,9 +214,9 @@ function serializeIPv4(address) {
|
|
|
214
214
|
let output = "";
|
|
215
215
|
let n = address;
|
|
216
216
|
|
|
217
|
-
for (let i =
|
|
217
|
+
for (let i = 1; i <= 4; ++i) {
|
|
218
218
|
output = String(n % 256) + output;
|
|
219
|
-
if (i !==
|
|
219
|
+
if (i !== 4) {
|
|
220
220
|
output = "." + output;
|
|
221
221
|
}
|
|
222
222
|
n = Math.floor(n / 256);
|
|
@@ -226,9 +226,9 @@ function serializeIPv4(address) {
|
|
|
226
226
|
}
|
|
227
227
|
|
|
228
228
|
function parseIPv6(input) {
|
|
229
|
-
const
|
|
230
|
-
let
|
|
231
|
-
let
|
|
229
|
+
const address = [0, 0, 0, 0, 0, 0, 0, 0];
|
|
230
|
+
let pieceIndex = 0;
|
|
231
|
+
let compress = null;
|
|
232
232
|
let pointer = 0;
|
|
233
233
|
|
|
234
234
|
input = punycode.ucs2.decode(input);
|
|
@@ -239,22 +239,22 @@ function parseIPv6(input) {
|
|
|
239
239
|
}
|
|
240
240
|
|
|
241
241
|
pointer += 2;
|
|
242
|
-
++
|
|
243
|
-
|
|
242
|
+
++pieceIndex;
|
|
243
|
+
compress = pieceIndex;
|
|
244
244
|
}
|
|
245
245
|
|
|
246
246
|
while (pointer < input.length) {
|
|
247
|
-
if (
|
|
247
|
+
if (pieceIndex === 8) {
|
|
248
248
|
return failure;
|
|
249
249
|
}
|
|
250
250
|
|
|
251
251
|
if (input[pointer] === 58) {
|
|
252
|
-
if (
|
|
252
|
+
if (compress !== null) {
|
|
253
253
|
return failure;
|
|
254
254
|
}
|
|
255
255
|
++pointer;
|
|
256
|
-
++
|
|
257
|
-
|
|
256
|
+
++pieceIndex;
|
|
257
|
+
compress = pieceIndex;
|
|
258
258
|
continue;
|
|
259
259
|
}
|
|
260
260
|
|
|
@@ -274,7 +274,7 @@ function parseIPv6(input) {
|
|
|
274
274
|
|
|
275
275
|
pointer -= length;
|
|
276
276
|
|
|
277
|
-
if (
|
|
277
|
+
if (pieceIndex > 6) {
|
|
278
278
|
return failure;
|
|
279
279
|
}
|
|
280
280
|
|
|
@@ -310,12 +310,12 @@ function parseIPv6(input) {
|
|
|
310
310
|
++pointer;
|
|
311
311
|
}
|
|
312
312
|
|
|
313
|
-
|
|
313
|
+
address[pieceIndex] = address[pieceIndex] * 0x100 + ipv4Piece;
|
|
314
314
|
|
|
315
315
|
++numbersSeen;
|
|
316
316
|
|
|
317
317
|
if (numbersSeen === 2 || numbersSeen === 4) {
|
|
318
|
-
++
|
|
318
|
+
++pieceIndex;
|
|
319
319
|
}
|
|
320
320
|
}
|
|
321
321
|
|
|
@@ -333,52 +333,50 @@ function parseIPv6(input) {
|
|
|
333
333
|
return failure;
|
|
334
334
|
}
|
|
335
335
|
|
|
336
|
-
|
|
337
|
-
++
|
|
336
|
+
address[pieceIndex] = value;
|
|
337
|
+
++pieceIndex;
|
|
338
338
|
}
|
|
339
339
|
|
|
340
|
-
if (
|
|
341
|
-
let swaps =
|
|
342
|
-
|
|
343
|
-
while (
|
|
344
|
-
const temp =
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
--
|
|
340
|
+
if (compress !== null) {
|
|
341
|
+
let swaps = pieceIndex - compress;
|
|
342
|
+
pieceIndex = 7;
|
|
343
|
+
while (pieceIndex !== 0 && swaps > 0) {
|
|
344
|
+
const temp = address[compress + swaps - 1];
|
|
345
|
+
address[compress + swaps - 1] = address[pieceIndex];
|
|
346
|
+
address[pieceIndex] = temp;
|
|
347
|
+
--pieceIndex;
|
|
348
348
|
--swaps;
|
|
349
349
|
}
|
|
350
|
-
} else if (
|
|
350
|
+
} else if (compress === null && pieceIndex !== 8) {
|
|
351
351
|
return failure;
|
|
352
352
|
}
|
|
353
353
|
|
|
354
|
-
return
|
|
354
|
+
return address;
|
|
355
355
|
}
|
|
356
356
|
|
|
357
357
|
function serializeIPv6(address) {
|
|
358
358
|
let output = "";
|
|
359
359
|
const seqResult = findLongestZeroSequence(address);
|
|
360
|
-
const
|
|
360
|
+
const compress = seqResult.idx;
|
|
361
361
|
let ignore0 = false;
|
|
362
362
|
|
|
363
|
-
for (let
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
if (ignore0 && piece === 0) {
|
|
363
|
+
for (let pieceIndex = 0; pieceIndex <= 7; ++pieceIndex) {
|
|
364
|
+
if (ignore0 && address[pieceIndex] === 0) {
|
|
367
365
|
continue;
|
|
368
366
|
} else if (ignore0) {
|
|
369
367
|
ignore0 = false;
|
|
370
368
|
}
|
|
371
369
|
|
|
372
|
-
if (
|
|
373
|
-
const separator =
|
|
370
|
+
if (compress === pieceIndex) {
|
|
371
|
+
const separator = pieceIndex === 0 ? "::" : ":";
|
|
374
372
|
output += separator;
|
|
375
373
|
ignore0 = true;
|
|
376
374
|
continue;
|
|
377
375
|
}
|
|
378
376
|
|
|
379
|
-
output +=
|
|
377
|
+
output += address[pieceIndex].toString(16);
|
|
380
378
|
|
|
381
|
-
if (
|
|
379
|
+
if (pieceIndex !== 7) {
|
|
382
380
|
output += ":";
|
|
383
381
|
}
|
|
384
382
|
}
|
|
@@ -1210,12 +1208,8 @@ function serializeURL(url, excludeFragment) {
|
|
|
1210
1208
|
}
|
|
1211
1209
|
|
|
1212
1210
|
function serializeOrigin(tuple) {
|
|
1213
|
-
if (tuple.scheme === undefined || tuple.host === undefined || tuple.port === undefined) {
|
|
1214
|
-
return "null";
|
|
1215
|
-
}
|
|
1216
|
-
|
|
1217
1211
|
let result = tuple.scheme + "://";
|
|
1218
|
-
result +=
|
|
1212
|
+
result += serializeHost(tuple.host);
|
|
1219
1213
|
|
|
1220
1214
|
if (tuple.port !== null) {
|
|
1221
1215
|
result += ":" + tuple.port;
|
|
@@ -1226,13 +1220,14 @@ function serializeOrigin(tuple) {
|
|
|
1226
1220
|
|
|
1227
1221
|
module.exports.serializeURL = serializeURL;
|
|
1228
1222
|
|
|
1229
|
-
module.exports.
|
|
1223
|
+
module.exports.serializeURLOrigin = function (url) {
|
|
1224
|
+
// https://url.spec.whatwg.org/#concept-url-origin
|
|
1230
1225
|
switch (url.scheme) {
|
|
1231
1226
|
case "blob":
|
|
1232
1227
|
try {
|
|
1233
|
-
return module.exports.
|
|
1228
|
+
return module.exports.serializeURLOrigin(module.exports.parseURL(url.path[0]));
|
|
1234
1229
|
} catch (e) {
|
|
1235
|
-
// serializing an opaque
|
|
1230
|
+
// serializing an opaque origin returns "null"
|
|
1236
1231
|
return "null";
|
|
1237
1232
|
}
|
|
1238
1233
|
case "ftp":
|
|
@@ -1243,14 +1238,14 @@ module.exports.serializeURLToUnicodeOrigin = function (url) {
|
|
|
1243
1238
|
case "wss":
|
|
1244
1239
|
return serializeOrigin({
|
|
1245
1240
|
scheme: url.scheme,
|
|
1246
|
-
host:
|
|
1241
|
+
host: url.host,
|
|
1247
1242
|
port: url.port
|
|
1248
1243
|
});
|
|
1249
1244
|
case "file":
|
|
1250
1245
|
// spec says "exercise to the reader", chrome says "file://"
|
|
1251
1246
|
return "file://";
|
|
1252
1247
|
default:
|
|
1253
|
-
// serializing an opaque
|
|
1248
|
+
// serializing an opaque origin returns "null"
|
|
1254
1249
|
return "null";
|
|
1255
1250
|
}
|
|
1256
1251
|
};
|