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 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 [fe6b25](https://github.com/whatwg/url/commit/fe6b251739e225555f04319f19c70c031a5d99eb).
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) [Unicode serializer](https://html.spec.whatwg.org/multipage/browsers.html#unicode-serialisation-of-an-origin): `serializeURLToUnicodeOrigin(urlRecord)`
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
@@ -38,7 +38,7 @@ exports.implementation = class URLImpl {
38
38
  }
39
39
 
40
40
  get origin() {
41
- return usm.serializeURLToUnicodeOrigin(this._url);
41
+ return usm.serializeURLOrigin(this._url);
42
42
  }
43
43
 
44
44
  get protocol() {
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.serializeURLToUnicodeOrigin = require("./url-state-machine").serializeURLToUnicodeOrigin;
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;
@@ -214,9 +214,9 @@ function serializeIPv4(address) {
214
214
  let output = "";
215
215
  let n = address;
216
216
 
217
- for (let i = 0; i < 4; ++i) {
217
+ for (let i = 1; i <= 4; ++i) {
218
218
  output = String(n % 256) + output;
219
- if (i !== 3) {
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 ip = [0, 0, 0, 0, 0, 0, 0, 0];
230
- let piecePtr = 0;
231
- let compressPtr = null;
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
- ++piecePtr;
243
- compressPtr = piecePtr;
242
+ ++pieceIndex;
243
+ compress = pieceIndex;
244
244
  }
245
245
 
246
246
  while (pointer < input.length) {
247
- if (piecePtr === 8) {
247
+ if (pieceIndex === 8) {
248
248
  return failure;
249
249
  }
250
250
 
251
251
  if (input[pointer] === 58) {
252
- if (compressPtr !== null) {
252
+ if (compress !== null) {
253
253
  return failure;
254
254
  }
255
255
  ++pointer;
256
- ++piecePtr;
257
- compressPtr = piecePtr;
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 (piecePtr > 6) {
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
- ip[piecePtr] = ip[piecePtr] * 0x100 + ipv4Piece;
313
+ address[pieceIndex] = address[pieceIndex] * 0x100 + ipv4Piece;
314
314
 
315
315
  ++numbersSeen;
316
316
 
317
317
  if (numbersSeen === 2 || numbersSeen === 4) {
318
- ++piecePtr;
318
+ ++pieceIndex;
319
319
  }
320
320
  }
321
321
 
@@ -333,52 +333,50 @@ function parseIPv6(input) {
333
333
  return failure;
334
334
  }
335
335
 
336
- ip[piecePtr] = value;
337
- ++piecePtr;
336
+ address[pieceIndex] = value;
337
+ ++pieceIndex;
338
338
  }
339
339
 
340
- if (compressPtr !== null) {
341
- let swaps = piecePtr - compressPtr;
342
- piecePtr = 7;
343
- while (piecePtr !== 0 && swaps > 0) {
344
- const temp = ip[compressPtr + swaps - 1]; // piece
345
- ip[compressPtr + swaps - 1] = ip[piecePtr];
346
- ip[piecePtr] = temp;
347
- --piecePtr;
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 (compressPtr === null && piecePtr !== 8) {
350
+ } else if (compress === null && pieceIndex !== 8) {
351
351
  return failure;
352
352
  }
353
353
 
354
- return ip;
354
+ return address;
355
355
  }
356
356
 
357
357
  function serializeIPv6(address) {
358
358
  let output = "";
359
359
  const seqResult = findLongestZeroSequence(address);
360
- const compressPtr = seqResult.idx;
360
+ const compress = seqResult.idx;
361
361
  let ignore0 = false;
362
362
 
363
- for (let i = 0; i < address.length; ++i) {
364
- const piece = address[i];
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 (compressPtr === i) {
373
- const separator = i === 0 ? "::" : ":";
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 += piece.toString(16);
377
+ output += address[pieceIndex].toString(16);
380
378
 
381
- if (i !== address.length - 1) {
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 += tr46.toUnicode(tuple.host, false).domain;
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.serializeURLToUnicodeOrigin = function (url) {
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.serializeURLToUnicodeOrigin(module.exports.parseURL(url.path[0]));
1228
+ return module.exports.serializeURLOrigin(module.exports.parseURL(url.path[0]));
1234
1229
  } catch (e) {
1235
- // serializing an opaque identifier returns "null"
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: serializeHost(url.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 identifier returns "null"
1248
+ // serializing an opaque origin returns "null"
1254
1249
  return "null";
1255
1250
  }
1256
1251
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "whatwg-url",
3
- "version": "4.8.0",
3
+ "version": "5.0.0",
4
4
  "description": "An implementation of the WHATWG URL Standard's URL API and parsing machinery",
5
5
  "main": "lib/public-api.js",
6
6
  "files": [