@csark0812/skeleton 3.0.1 → 4.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.
@@ -3027,7 +3027,25 @@ var require_utils = __commonJS((exports, module) => {
3027
3027
  var isIPv4 = RegExp.prototype.test.bind(/^(?:(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)\.){3}(?:25[0-5]|2[0-4]\d|1\d{2}|[1-9]\d|\d)$/u);
3028
3028
  var isHexPair = RegExp.prototype.test.bind(/^[\da-f]{2}$/iu);
3029
3029
  var isUnreserved = RegExp.prototype.test.bind(/^[\da-z\-._~]$/iu);
3030
- var isPathCharacter = RegExp.prototype.test.bind(/^[\da-z\-._~!$&'()*+,;=:@/]$/iu);
3030
+ var isPathCharacter = RegExp.prototype.test.bind(/^[A-Za-z0-9\-._~!$&'()*+,;=:@/]$/u);
3031
+ var isQueryFragmentCharacter = RegExp.prototype.test.bind(/^[A-Za-z0-9\-._~!$&'()*+,;=:@/?]$/u);
3032
+ var isUserinfoCharacter = RegExp.prototype.test.bind(/^[A-Za-z0-9\-._~!$&'()*+,;=:]$/u);
3033
+ var BYTE_HEX = new Array(256);
3034
+ {
3035
+ const HEX_DIGITS = "0123456789ABCDEF";
3036
+ for (let i = 0;i < 256; i++) {
3037
+ BYTE_HEX[i] = "%" + HEX_DIGITS[i >> 4] + HEX_DIGITS[i & 15];
3038
+ }
3039
+ }
3040
+ function percentEncodeNonAscii(cp) {
3041
+ if (cp < 2048) {
3042
+ return BYTE_HEX[192 | cp >> 6] + BYTE_HEX[128 | cp & 63];
3043
+ }
3044
+ if (cp < 65536) {
3045
+ return BYTE_HEX[224 | cp >> 12] + BYTE_HEX[128 | cp >> 6 & 63] + BYTE_HEX[128 | cp & 63];
3046
+ }
3047
+ return BYTE_HEX[240 | cp >> 18] + BYTE_HEX[128 | cp >> 12 & 63] + BYTE_HEX[128 | cp >> 6 & 63] + BYTE_HEX[128 | cp & 63];
3048
+ }
3031
3049
  function stringArrayToHexStripped(input) {
3032
3050
  let acc = "";
3033
3051
  let code = 0;
@@ -3052,91 +3070,122 @@ var require_utils = __commonJS((exports, module) => {
3052
3070
  }
3053
3071
  return acc;
3054
3072
  }
3073
+ var isHextet = RegExp.prototype.test.bind(/^[\dA-Fa-f]{1,4}$/);
3074
+ var isIPvFuture = RegExp.prototype.test.bind(/^[vV][\dA-Fa-f]+\.[A-Za-z\d\-._~!$&'()*+,;=:]+$/);
3075
+ var isZoneCharacter = RegExp.prototype.test.bind(/^[A-Za-z\d\-._~]$/);
3055
3076
  var nonSimpleDomain = RegExp.prototype.test.bind(/[^!"$&'()*+,\-.;=_`a-z{}~]/u);
3056
- function consumeIsZone(buffer) {
3057
- buffer.length = 0;
3058
- return true;
3059
- }
3060
- function consumeHextets(buffer, address, output) {
3061
- if (buffer.length) {
3062
- const hex = stringArrayToHexStripped(buffer);
3063
- if (hex !== "") {
3064
- address.push(hex);
3065
- } else {
3066
- output.error = true;
3067
- return false;
3077
+ function isZoneIdentifier(zone) {
3078
+ if (zone.length === 0)
3079
+ return false;
3080
+ for (let i = 0;i < zone.length; i++) {
3081
+ if (isZoneCharacter(zone[i]))
3082
+ continue;
3083
+ if (zone[i] === "%" && i + 2 < zone.length && isHexPair(zone.slice(i + 1, i + 3))) {
3084
+ i += 2;
3085
+ continue;
3068
3086
  }
3069
- buffer.length = 0;
3087
+ return false;
3070
3088
  }
3071
3089
  return true;
3072
3090
  }
3073
- function getIPV6(input) {
3074
- let tokenCount = 0;
3075
- const output = { error: false, address: "", zone: "" };
3076
- const address = [];
3077
- const buffer = [];
3078
- let endipv6Encountered = false;
3079
- let endIpv6 = false;
3080
- let consume = consumeHextets;
3081
- for (let i = 0;i < input.length; i++) {
3082
- const cursor = input[i];
3083
- if (cursor === "[" || cursor === "]") {
3084
- continue;
3085
- }
3086
- if (cursor === ":") {
3087
- if (endipv6Encountered === true) {
3088
- endIpv6 = true;
3089
- }
3090
- if (!consume(buffer, address, output)) {
3091
- break;
3091
+ function compressIPv6ZeroRun(hextets) {
3092
+ let bestStart = -1;
3093
+ let bestLength = 0;
3094
+ let runStart = -1;
3095
+ let runLength = 0;
3096
+ for (let i = 0;i < hextets.length; i++) {
3097
+ if (hextets[i] === "0") {
3098
+ if (runStart === -1)
3099
+ runStart = i;
3100
+ runLength++;
3101
+ if (runLength > bestLength) {
3102
+ bestLength = runLength;
3103
+ bestStart = runStart;
3092
3104
  }
3093
- if (++tokenCount > 7) {
3094
- output.error = true;
3095
- break;
3096
- }
3097
- if (i > 0 && input[i - 1] === ":") {
3098
- endipv6Encountered = true;
3099
- }
3100
- address.push(":");
3101
- continue;
3102
- } else if (cursor === "%") {
3103
- if (!consume(buffer, address, output)) {
3104
- break;
3105
- }
3106
- consume = consumeIsZone;
3107
3105
  } else {
3108
- buffer.push(cursor);
3109
- continue;
3106
+ runStart = -1;
3107
+ runLength = 0;
3110
3108
  }
3111
3109
  }
3112
- if (buffer.length) {
3113
- if (consume === consumeIsZone) {
3114
- output.zone = buffer.join("");
3115
- } else if (endIpv6) {
3116
- address.push(buffer.join(""));
3117
- } else {
3118
- address.push(stringArrayToHexStripped(buffer));
3110
+ if (bestLength < 2)
3111
+ return hextets.join(":");
3112
+ const head = hextets.slice(0, bestStart).join(":");
3113
+ const tail = hextets.slice(bestStart + bestLength).join(":");
3114
+ return head + "::" + tail;
3115
+ }
3116
+ function normalizeIPv6Address(input) {
3117
+ const compression = input.indexOf("::");
3118
+ if (compression !== -1 && input.indexOf("::", compression + 1) !== -1)
3119
+ return;
3120
+ const left = compression === -1 ? input.split(":") : input.slice(0, compression).split(":");
3121
+ const right = compression === -1 ? [] : input.slice(compression + 2).split(":");
3122
+ if (compression !== -1) {
3123
+ if (left.length === 1 && left[0] === "")
3124
+ left.length = 0;
3125
+ if (right.length === 1 && right[0] === "")
3126
+ right.length = 0;
3127
+ }
3128
+ const parts = left.concat(right);
3129
+ let hextetCount = 0;
3130
+ for (let i = 0;i < parts.length; i++) {
3131
+ const part = parts[i];
3132
+ if (part === "")
3133
+ return;
3134
+ if (part.indexOf(".") !== -1) {
3135
+ if (i !== parts.length - 1 || compression !== -1 && right.length === 0 || !isIPv4(part))
3136
+ return;
3137
+ hextetCount += 2;
3138
+ continue;
3119
3139
  }
3140
+ if (!isHextet(part))
3141
+ return;
3142
+ parts[i] = parseInt(part, 16).toString(16);
3143
+ hextetCount++;
3120
3144
  }
3121
- output.address = address.join("");
3122
- return output;
3145
+ if (compression === -1) {
3146
+ if (hextetCount !== 8)
3147
+ return;
3148
+ return compressIPv6ZeroRun(parts);
3149
+ }
3150
+ if (hextetCount >= 8)
3151
+ return;
3152
+ const expanded = parts.slice(0, left.length);
3153
+ for (let i = hextetCount;i < 8; i++)
3154
+ expanded.push("0");
3155
+ for (let i = left.length;i < parts.length; i++)
3156
+ expanded.push(parts[i]);
3157
+ return compressIPv6ZeroRun(expanded);
3123
3158
  }
3124
3159
  function normalizeIPv6(host) {
3125
- if (findToken(host, ":") < 2) {
3126
- return { host, isIPV6: false };
3127
- }
3128
- const ipv6 = getIPV6(host);
3129
- if (!ipv6.error) {
3130
- let newHost = ipv6.address;
3131
- let escapedHost = ipv6.address;
3132
- if (ipv6.zone) {
3133
- newHost += "%" + ipv6.zone;
3134
- escapedHost += "%25" + ipv6.zone;
3135
- }
3136
- return { host: newHost, isIPV6: true, escapedHost };
3137
- } else {
3138
- return { host, isIPV6: false };
3139
- }
3160
+ const bracketed = host[0] === "[" && host[host.length - 1] === "]";
3161
+ const hasBracket = host[0] === "[" || host[host.length - 1] === "]";
3162
+ if (hasBracket && !bracketed)
3163
+ return { host, isIPV6: false, error: true };
3164
+ let input = bracketed ? host.slice(1, -1) : host;
3165
+ if (bracketed && isIPvFuture(input)) {
3166
+ input = input.toLowerCase();
3167
+ return { host: `[${input}]`, escapedHost: input, isIPV6: false, isIPVFuture: true };
3168
+ }
3169
+ if (findToken(input, ":") < 2) {
3170
+ return { host, isIPV6: false, error: bracketed };
3171
+ }
3172
+ let zoneIdentifier = "";
3173
+ const zoneSeparator = input.indexOf("%");
3174
+ if (zoneSeparator !== -1) {
3175
+ const separatorLength = input.slice(zoneSeparator, zoneSeparator + 3).toLowerCase() === "%25" ? 3 : 1;
3176
+ zoneIdentifier = input.slice(zoneSeparator + separatorLength);
3177
+ if (!isZoneIdentifier(zoneIdentifier))
3178
+ return { host, isIPV6: false, error: true };
3179
+ input = input.slice(0, zoneSeparator);
3180
+ }
3181
+ const address = normalizeIPv6Address(input);
3182
+ if (address === undefined)
3183
+ return { host, isIPV6: false, error: true };
3184
+ return {
3185
+ host: address + (zoneIdentifier ? "%" + zoneIdentifier : ""),
3186
+ escapedHost: address + (zoneIdentifier ? "%25" + zoneIdentifier : ""),
3187
+ isIPV6: true
3188
+ };
3140
3189
  }
3141
3190
  function findToken(str, token) {
3142
3191
  let ind = 0;
@@ -3256,7 +3305,8 @@ var require_utils = __commonJS((exports, module) => {
3256
3305
  function normalizePathEncoding(input) {
3257
3306
  let output = "";
3258
3307
  for (let i = 0;i < input.length; i++) {
3259
- if (input[i] === "%" && i + 2 < input.length) {
3308
+ const ch = input[i];
3309
+ if (ch === "%" && i + 2 < input.length) {
3260
3310
  const hex = input.slice(i + 1, i + 3);
3261
3311
  if (isHexPair(hex)) {
3262
3312
  const normalizedHex = hex.toUpperCase();
@@ -3270,10 +3320,152 @@ var require_utils = __commonJS((exports, module) => {
3270
3320
  continue;
3271
3321
  }
3272
3322
  }
3273
- if (isPathCharacter(input[i])) {
3274
- output += input[i];
3323
+ if (isPathCharacter(ch)) {
3324
+ output += ch;
3325
+ } else {
3326
+ const code = input.charCodeAt(i);
3327
+ if (code < 128) {
3328
+ output += isEscapeSafe(code) ? ch : BYTE_HEX[code];
3329
+ } else if (code < 55296 || code > 57343) {
3330
+ output += percentEncodeNonAscii(code);
3331
+ } else if (code <= 56319 && i + 1 < input.length) {
3332
+ const low = input.charCodeAt(i + 1);
3333
+ if (low >= 56320 && low <= 57343) {
3334
+ output += percentEncodeNonAscii(65536 + (code - 55296 << 10) + (low - 56320));
3335
+ i++;
3336
+ } else {
3337
+ output += percentEncodeNonAscii(65533);
3338
+ }
3339
+ } else {
3340
+ output += percentEncodeNonAscii(65533);
3341
+ }
3342
+ }
3343
+ }
3344
+ return output;
3345
+ }
3346
+ function serializePathEncoding(input, pathNoScheme = false) {
3347
+ let output = "";
3348
+ let firstSegment = pathNoScheme && input[0] !== "/";
3349
+ for (let i = 0;i < input.length; i++) {
3350
+ const ch = input[i];
3351
+ if (ch === "%" && i + 2 < input.length) {
3352
+ const hex = input.slice(i + 1, i + 3);
3353
+ if (isHexPair(hex)) {
3354
+ output += "%" + hex.toUpperCase();
3355
+ i += 2;
3356
+ continue;
3357
+ }
3358
+ }
3359
+ if (ch === "/") {
3360
+ firstSegment = false;
3361
+ }
3362
+ if (isPathCharacter(ch) && (ch !== ":" || !firstSegment)) {
3363
+ output += ch;
3364
+ } else {
3365
+ const code = input.charCodeAt(i);
3366
+ if (code < 128) {
3367
+ output += BYTE_HEX[code];
3368
+ } else if (code < 55296 || code > 57343) {
3369
+ output += percentEncodeNonAscii(code);
3370
+ } else if (code <= 56319 && i + 1 < input.length) {
3371
+ const low = input.charCodeAt(i + 1);
3372
+ if (low >= 56320 && low <= 57343) {
3373
+ output += percentEncodeNonAscii(65536 + (code - 55296 << 10) + (low - 56320));
3374
+ i++;
3375
+ } else {
3376
+ output += percentEncodeNonAscii(65533);
3377
+ }
3378
+ } else {
3379
+ output += percentEncodeNonAscii(65533);
3380
+ }
3381
+ }
3382
+ }
3383
+ return output;
3384
+ }
3385
+ function encodeComponent(input, isAllowed) {
3386
+ let output = "";
3387
+ for (let i = 0;i < input.length; i++) {
3388
+ const ch = input[i];
3389
+ if (ch === "%" && i + 2 < input.length) {
3390
+ const hex = input.slice(i + 1, i + 3);
3391
+ if (isHexPair(hex)) {
3392
+ output += "%" + hex.toUpperCase();
3393
+ i += 2;
3394
+ continue;
3395
+ }
3396
+ }
3397
+ if (isAllowed(ch)) {
3398
+ output += ch;
3399
+ } else {
3400
+ const code = input.charCodeAt(i);
3401
+ if (code < 128) {
3402
+ output += BYTE_HEX[code];
3403
+ } else if (code < 55296 || code > 57343) {
3404
+ output += percentEncodeNonAscii(code);
3405
+ } else if (code <= 56319 && i + 1 < input.length) {
3406
+ const low = input.charCodeAt(i + 1);
3407
+ if (low >= 56320 && low <= 57343) {
3408
+ output += percentEncodeNonAscii(65536 + (code - 55296 << 10) + (low - 56320));
3409
+ i++;
3410
+ } else {
3411
+ output += percentEncodeNonAscii(65533);
3412
+ }
3413
+ } else {
3414
+ output += percentEncodeNonAscii(65533);
3415
+ }
3416
+ }
3417
+ }
3418
+ return output;
3419
+ }
3420
+ function encodeUserinfo(input) {
3421
+ return encodeComponent(input, isUserinfoCharacter);
3422
+ }
3423
+ function encodeQuery(input) {
3424
+ return encodeComponent(input, isQueryFragmentCharacter);
3425
+ }
3426
+ function encodeFragment(input) {
3427
+ return encodeComponent(input, isQueryFragmentCharacter);
3428
+ }
3429
+ function isEscapeSafe(cp) {
3430
+ return cp >= 48 && cp <= 57 || cp >= 65 && cp <= 90 || cp >= 97 && cp <= 122 || cp === 42 || cp === 43 || cp === 45 || cp === 46 || cp === 47 || cp === 64 || cp === 95;
3431
+ }
3432
+ function normalizeQueryFragmentEncoding(input) {
3433
+ let output = "";
3434
+ for (let i = 0;i < input.length; i++) {
3435
+ const ch = input[i];
3436
+ if (ch === "%" && i + 2 < input.length) {
3437
+ const hex = input.slice(i + 1, i + 3);
3438
+ if (isHexPair(hex)) {
3439
+ const normalizedHex = hex.toUpperCase();
3440
+ const decoded = String.fromCharCode(parseInt(normalizedHex, 16));
3441
+ if (isUnreserved(decoded)) {
3442
+ output += decoded;
3443
+ } else {
3444
+ output += "%" + normalizedHex;
3445
+ }
3446
+ i += 2;
3447
+ continue;
3448
+ }
3449
+ }
3450
+ if (isQueryFragmentCharacter(ch)) {
3451
+ output += ch;
3275
3452
  } else {
3276
- output += escape(input[i]);
3453
+ const code = input.charCodeAt(i);
3454
+ if (code < 128) {
3455
+ output += isEscapeSafe(code) ? ch : BYTE_HEX[code];
3456
+ } else if (code < 55296 || code > 57343) {
3457
+ output += percentEncodeNonAscii(code);
3458
+ } else if (code <= 56319 && i + 1 < input.length) {
3459
+ const low = input.charCodeAt(i + 1);
3460
+ if (low >= 56320 && low <= 57343) {
3461
+ output += percentEncodeNonAscii(65536 + (code - 55296 << 10) + (low - 56320));
3462
+ i++;
3463
+ } else {
3464
+ output += percentEncodeNonAscii(65533);
3465
+ }
3466
+ } else {
3467
+ output += percentEncodeNonAscii(65533);
3468
+ }
3277
3469
  }
3278
3470
  }
3279
3471
  return output;
@@ -3296,14 +3488,18 @@ var require_utils = __commonJS((exports, module) => {
3296
3488
  function recomposeAuthority(component) {
3297
3489
  const uriTokens = [];
3298
3490
  if (component.userinfo !== undefined) {
3299
- uriTokens.push(component.userinfo);
3491
+ uriTokens.push(encodeUserinfo(component.userinfo));
3300
3492
  uriTokens.push("@");
3301
3493
  }
3302
3494
  if (component.host !== undefined) {
3303
- let host = unescape(component.host);
3495
+ let host = component.host;
3304
3496
  if (!isIPv4(host)) {
3305
- const ipV6res = normalizeIPv6(host);
3306
- if (ipV6res.isIPV6 === true) {
3497
+ let ipV6res = normalizeIPv6(host);
3498
+ if (ipV6res.isIPV6 !== true && ipV6res.isIPVFuture !== true) {
3499
+ host = normalizePercentEncoding(host, true);
3500
+ ipV6res = normalizeIPv6(host);
3501
+ }
3502
+ if (ipV6res.isIPV6 === true || ipV6res.isIPVFuture === true) {
3307
3503
  host = `[${ipV6res.escapedHost}]`;
3308
3504
  } else {
3309
3505
  host = reescapeHostDelimiters(host, false);
@@ -3323,6 +3519,11 @@ var require_utils = __commonJS((exports, module) => {
3323
3519
  reescapeHostDelimiters,
3324
3520
  normalizePercentEncoding,
3325
3521
  normalizePathEncoding,
3522
+ serializePathEncoding,
3523
+ normalizeQueryFragmentEncoding,
3524
+ encodeUserinfo,
3525
+ encodeQuery,
3526
+ encodeFragment,
3326
3527
  escapePreservingEscapes,
3327
3528
  removeDotSegments,
3328
3529
  isIPv4,
@@ -3335,7 +3536,7 @@ var require_utils = __commonJS((exports, module) => {
3335
3536
  // node_modules/fast-uri/lib/schemes.js
3336
3537
  var require_schemes = __commonJS((exports, module) => {
3337
3538
  var { isUUID } = require_utils();
3338
- var URN_REG = /([\da-z][\d\-a-z]{0,31}):((?:[\w!$'()*+,\-.:;=@]|%[\da-f]{2})+)/iu;
3539
+ var URN_REG = /^([\da-z][\d\-a-z]{0,31}):((?:[\w!$'()*+,\-./:;=@]|%[\da-f]{2})+)$/iu;
3339
3540
  var supportedSchemeNames = [
3340
3541
  "http",
3341
3542
  "https",
@@ -3390,9 +3591,10 @@ var require_schemes = __commonJS((exports, module) => {
3390
3591
  wsComponent.secure = undefined;
3391
3592
  }
3392
3593
  if (wsComponent.resourceName) {
3393
- const [path, query] = wsComponent.resourceName.split("?");
3594
+ const queryIndex = wsComponent.resourceName.indexOf("?");
3595
+ const path = queryIndex === -1 ? wsComponent.resourceName : wsComponent.resourceName.slice(0, queryIndex);
3394
3596
  wsComponent.path = path && path !== "/" ? path : undefined;
3395
- wsComponent.query = query;
3597
+ wsComponent.query = queryIndex === -1 ? undefined : wsComponent.resourceName.slice(queryIndex + 1);
3396
3598
  wsComponent.resourceName = undefined;
3397
3599
  }
3398
3600
  wsComponent.fragment = undefined;
@@ -3404,7 +3606,7 @@ var require_schemes = __commonJS((exports, module) => {
3404
3606
  return urnComponent;
3405
3607
  }
3406
3608
  const matches = urnComponent.path.match(URN_REG);
3407
- if (matches) {
3609
+ if (matches && matches[0] === urnComponent.path) {
3408
3610
  const scheme = options.scheme || urnComponent.scheme || "urn";
3409
3611
  urnComponent.nid = matches[1].toLowerCase();
3410
3612
  urnComponent.nss = matches[2];
@@ -3508,8 +3710,17 @@ var require_schemes = __commonJS((exports, module) => {
3508
3710
 
3509
3711
  // node_modules/fast-uri/index.js
3510
3712
  var require_fast_uri = __commonJS((exports, module) => {
3511
- var { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizePercentEncoding, normalizePathEncoding, escapePreservingEscapes, reescapeHostDelimiters, isIPv4, nonSimpleDomain } = require_utils();
3713
+ var { normalizeIPv6, removeDotSegments, recomposeAuthority, normalizePercentEncoding, normalizePathEncoding, serializePathEncoding, normalizeQueryFragmentEncoding, encodeQuery, encodeFragment, reescapeHostDelimiters, isIPv4, nonSimpleDomain } = require_utils();
3512
3714
  var { SCHEMES, getSchemeHandler } = require_schemes();
3715
+ var VALID_SCHEME = /^[A-Za-z][A-Za-z0-9+.-]*$/u;
3716
+ var MALFORMED_SCHEME_ERROR = "URI scheme is malformed.";
3717
+ function decodeValidScheme(scheme) {
3718
+ const decodedScheme = unescape(String(scheme));
3719
+ if (!VALID_SCHEME.test(decodedScheme)) {
3720
+ throw new TypeError(MALFORMED_SCHEME_ERROR);
3721
+ }
3722
+ return decodedScheme;
3723
+ }
3513
3724
  function normalize(uri, options) {
3514
3725
  if (typeof uri === "string") {
3515
3726
  uri = normalizeString(uri, options);
@@ -3520,12 +3731,34 @@ var require_fast_uri = __commonJS((exports, module) => {
3520
3731
  }
3521
3732
  function resolve(baseURI, relativeURI, options) {
3522
3733
  const schemelessOptions = options ? Object.assign({ scheme: "null" }, options) : { scheme: "null" };
3523
- const { parsed: baseParsed, malformedAuthorityOrPort: baseMalformed } = parseWithStatus(baseURI, schemelessOptions);
3524
- const { parsed: relativeParsed, malformedAuthorityOrPort: relativeMalformed } = parseWithStatus(relativeURI, schemelessOptions);
3525
- if (baseMalformed || relativeMalformed) {
3734
+ const {
3735
+ parsed: baseParsed,
3736
+ malformedAuthorityOrPort: baseMalformed,
3737
+ malformedPercentEncoding: baseMalformedPercentEncoding,
3738
+ malformedSchemeSpecific: baseMalformedSchemeSpecific,
3739
+ malformedHost: baseMalformedHost,
3740
+ malformedScheme: baseMalformedScheme
3741
+ } = parseWithStatus(baseURI, schemelessOptions);
3742
+ const {
3743
+ parsed: relativeParsed,
3744
+ malformedAuthorityOrPort: relativeMalformed,
3745
+ malformedPercentEncoding: relativeMalformedPercentEncoding,
3746
+ malformedSchemeSpecific: relativeMalformedSchemeSpecific,
3747
+ malformedHost: relativeMalformedHost,
3748
+ malformedScheme: relativeMalformedScheme
3749
+ } = parseWithStatus(relativeURI, schemelessOptions);
3750
+ if (baseMalformed || relativeMalformed || baseMalformedPercentEncoding || relativeMalformedPercentEncoding || baseMalformedSchemeSpecific || relativeMalformedSchemeSpecific || baseMalformedHost || relativeMalformedHost || baseMalformedScheme || relativeMalformedScheme) {
3526
3751
  throw new Error(baseParsed.error || relativeParsed.error || "URI is malformed.");
3527
3752
  }
3528
3753
  const resolved = resolveComponent(baseParsed, relativeParsed, schemelessOptions, true);
3754
+ const resolvedSchemeHandler = getSchemeHandler(options && options.scheme || resolved.scheme);
3755
+ const resolvedHost = resolved.host;
3756
+ const resolvedHostIsIP = resolvedHost !== undefined && resolvedHost !== "" && (isIPv4(resolvedHost) || normalizeIPv6(resolvedHost).isIPV6);
3757
+ canonicalizeHost(resolved, options || {}, resolvedSchemeHandler, resolvedHostIsIP);
3758
+ const encodedASCIIHost = resolvedHost && resolvedHost.indexOf("%") !== -1 && !/\P{ASCII}/u.test(resolvedHost);
3759
+ if (resolved.error && !encodedASCIIHost) {
3760
+ throw new Error(resolved.error);
3761
+ }
3529
3762
  schemelessOptions.skipEscape = true;
3530
3763
  return serialize(resolved, schemelessOptions);
3531
3764
  }
@@ -3585,7 +3818,7 @@ var require_fast_uri = __commonJS((exports, module) => {
3585
3818
  function equal(uriA, uriB, options) {
3586
3819
  const normalizedA = normalizeComparableURI(uriA, options);
3587
3820
  const normalizedB = normalizeComparableURI(uriB, options);
3588
- return normalizedA !== undefined && normalizedB !== undefined && normalizedA.toLowerCase() === normalizedB.toLowerCase();
3821
+ return normalizedA !== undefined && normalizedB !== undefined && normalizedA === normalizedB;
3589
3822
  }
3590
3823
  function serialize(cmpts, opts) {
3591
3824
  const component = {
@@ -3606,20 +3839,23 @@ var require_fast_uri = __commonJS((exports, module) => {
3606
3839
  };
3607
3840
  const options = Object.assign({}, opts);
3608
3841
  const uriTokens = [];
3842
+ if (component.scheme) {
3843
+ component.scheme = decodeValidScheme(component.scheme);
3844
+ }
3609
3845
  const schemeHandler = getSchemeHandler(options.scheme || component.scheme);
3610
3846
  if (schemeHandler && schemeHandler.serialize)
3611
3847
  schemeHandler.serialize(component, options);
3848
+ const hasAuthority = component.userinfo !== undefined || component.host !== undefined || component.port !== undefined;
3849
+ const pathNoScheme = !options.skipEscape && component.scheme === undefined && !hasAuthority;
3612
3850
  if (component.path !== undefined) {
3613
3851
  if (!options.skipEscape) {
3614
- component.path = escapePreservingEscapes(component.path);
3615
- if (component.scheme !== undefined) {
3616
- component.path = component.path.split("%3A").join(":");
3617
- }
3852
+ component.path = serializePathEncoding(component.path, pathNoScheme);
3618
3853
  } else {
3619
3854
  component.path = normalizePercentEncoding(component.path);
3620
3855
  }
3621
3856
  }
3622
3857
  if (options.reference !== "suffix" && component.scheme) {
3858
+ component.scheme = decodeValidScheme(component.scheme);
3623
3859
  uriTokens.push(component.scheme, ":");
3624
3860
  }
3625
3861
  const authority = recomposeAuthority(component);
@@ -3637,16 +3873,19 @@ var require_fast_uri = __commonJS((exports, module) => {
3637
3873
  if (!options.absolutePath && (!schemeHandler || !schemeHandler.absolutePath)) {
3638
3874
  s = removeDotSegments(s);
3639
3875
  }
3876
+ if (pathNoScheme) {
3877
+ s = serializePathEncoding(s, true);
3878
+ }
3640
3879
  if (authority === undefined && s[0] === "/" && s[1] === "/") {
3641
3880
  s = "/%2F" + s.slice(2);
3642
3881
  }
3643
3882
  uriTokens.push(s);
3644
3883
  }
3645
3884
  if (component.query !== undefined) {
3646
- uriTokens.push("?", component.query);
3885
+ uriTokens.push("?", encodeQuery(component.query));
3647
3886
  }
3648
3887
  if (component.fragment !== undefined) {
3649
- uriTokens.push("#", component.fragment);
3888
+ uriTokens.push("#", encodeFragment(component.fragment));
3650
3889
  }
3651
3890
  return uriTokens.join("");
3652
3891
  }
@@ -3662,6 +3901,33 @@ var require_fast_uri = __commonJS((exports, module) => {
3662
3901
  }
3663
3902
  return;
3664
3903
  }
3904
+ function hasMalformedPercentEncoding(component) {
3905
+ if (component === undefined)
3906
+ return false;
3907
+ let percent = component.indexOf("%");
3908
+ while (percent !== -1) {
3909
+ if (percent + 2 >= component.length || !/^[\da-f]{2}$/iu.test(component.slice(percent + 1, percent + 3))) {
3910
+ return true;
3911
+ }
3912
+ percent = component.indexOf("%", percent + 3);
3913
+ }
3914
+ return false;
3915
+ }
3916
+ function hasMalformedComponentPercentEncoding(matches) {
3917
+ const host = matches[4];
3918
+ return hasMalformedPercentEncoding(matches[3]) || host !== undefined && !(host[0] === "[" && host[host.length - 1] === "]") && hasMalformedPercentEncoding(host) || hasMalformedPercentEncoding(matches[6]) || hasMalformedPercentEncoding(matches[7]) || hasMalformedPercentEncoding(matches[8]);
3919
+ }
3920
+ function canonicalizeHost(parsed, options, schemeHandler, isIP) {
3921
+ if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport) && parsed.host && parsed.host[0] !== "[" && (options.domainHost || schemeHandler && schemeHandler.domainHost) && isIP === false && nonSimpleDomain(parsed.host)) {
3922
+ try {
3923
+ parsed.host = new URL("http://" + parsed.host).hostname;
3924
+ } catch (e) {
3925
+ parsed.error = parsed.error || "Host's domain name can not be converted to ASCII: " + e;
3926
+ return true;
3927
+ }
3928
+ }
3929
+ return false;
3930
+ }
3665
3931
  function parseWithStatus(uri, opts) {
3666
3932
  const options = Object.assign({}, opts);
3667
3933
  const parsed = {
@@ -3674,6 +3940,11 @@ var require_fast_uri = __commonJS((exports, module) => {
3674
3940
  fragment: undefined
3675
3941
  };
3676
3942
  let malformedAuthorityOrPort = false;
3943
+ let malformedPercentEncoding = false;
3944
+ let malformedSchemeSpecific = false;
3945
+ let malformedHost = false;
3946
+ let malformedIPLiteral = false;
3947
+ let malformedScheme = false;
3677
3948
  let isIP = false;
3678
3949
  if (options.reference === "suffix") {
3679
3950
  if (options.scheme) {
@@ -3710,6 +3981,19 @@ var require_fast_uri = __commonJS((exports, module) => {
3710
3981
  parsed.path = matches[6] || "";
3711
3982
  parsed.query = matches[7];
3712
3983
  parsed.fragment = matches[8];
3984
+ if (parsed.scheme !== undefined) {
3985
+ const decodedScheme = unescape(parsed.scheme);
3986
+ if (VALID_SCHEME.test(decodedScheme)) {
3987
+ parsed.scheme = decodedScheme.toLowerCase();
3988
+ } else {
3989
+ parsed.error = parsed.error || MALFORMED_SCHEME_ERROR;
3990
+ malformedScheme = true;
3991
+ }
3992
+ }
3993
+ malformedPercentEncoding = hasMalformedComponentPercentEncoding(matches);
3994
+ if (malformedPercentEncoding) {
3995
+ parsed.error = parsed.error || "URI contains malformed percent-encoding.";
3996
+ }
3713
3997
  if (isNaN(parsed.port)) {
3714
3998
  parsed.port = matches[5];
3715
3999
  }
@@ -3721,9 +4005,15 @@ var require_fast_uri = __commonJS((exports, module) => {
3721
4005
  if (parsed.host) {
3722
4006
  const ipv4result = isIPv4(parsed.host);
3723
4007
  if (ipv4result === false) {
4008
+ const bracketedIPLiteral = parsed.host[0] === "[" && parsed.host[parsed.host.length - 1] === "]";
3724
4009
  const ipv6result = normalizeIPv6(parsed.host);
3725
- parsed.host = ipv6result.host.toLowerCase();
3726
- isIP = ipv6result.isIPV6;
4010
+ isIP = ipv6result.isIPV6 || ipv6result.isIPVFuture === true;
4011
+ malformedIPLiteral = bracketedIPLiteral && ipv6result.error === true;
4012
+ parsed.host = isIP ? ipv6result.host : ipv6result.host.toLowerCase();
4013
+ if (malformedIPLiteral) {
4014
+ parsed.error = parsed.error || "URI host is malformed.";
4015
+ malformedAuthorityOrPort = true;
4016
+ }
3727
4017
  } else {
3728
4018
  isIP = true;
3729
4019
  }
@@ -3741,42 +4031,34 @@ var require_fast_uri = __commonJS((exports, module) => {
3741
4031
  parsed.error = parsed.error || "URI is not a " + options.reference + " reference.";
3742
4032
  }
3743
4033
  const schemeHandler = getSchemeHandler(options.scheme || parsed.scheme);
3744
- if (!options.unicodeSupport && (!schemeHandler || !schemeHandler.unicodeSupport)) {
3745
- if (parsed.host && (options.domainHost || schemeHandler && schemeHandler.domainHost) && isIP === false && nonSimpleDomain(parsed.host)) {
3746
- try {
3747
- parsed.host = new URL("http://" + parsed.host).hostname;
3748
- } catch (e) {
3749
- parsed.error = parsed.error || "Host's domain name can not be converted to ASCII: " + e;
3750
- }
3751
- }
3752
- }
4034
+ malformedHost = canonicalizeHost(parsed, options, schemeHandler, isIP);
3753
4035
  if (!schemeHandler || schemeHandler && !schemeHandler.skipNormalize) {
3754
4036
  if (uri.indexOf("%") !== -1) {
3755
- if (parsed.scheme !== undefined) {
3756
- parsed.scheme = unescape(parsed.scheme);
3757
- }
3758
- if (parsed.host !== undefined) {
3759
- parsed.host = reescapeHostDelimiters(unescape(parsed.host), isIP);
4037
+ if (parsed.host !== undefined && !malformedIPLiteral) {
4038
+ const host = isIP ? parsed.host : normalizePercentEncoding(parsed.host, true);
4039
+ parsed.host = reescapeHostDelimiters(host, isIP);
3760
4040
  }
3761
4041
  }
3762
4042
  if (parsed.path) {
3763
4043
  parsed.path = normalizePathEncoding(parsed.path);
3764
4044
  }
4045
+ if (parsed.query) {
4046
+ parsed.query = normalizeQueryFragmentEncoding(parsed.query);
4047
+ }
3765
4048
  if (parsed.fragment) {
3766
- try {
3767
- parsed.fragment = encodeURI(decodeURIComponent(parsed.fragment));
3768
- } catch {
3769
- parsed.error = parsed.error || "URI malformed";
3770
- }
4049
+ parsed.fragment = normalizeQueryFragmentEncoding(parsed.fragment);
3771
4050
  }
3772
4051
  }
3773
4052
  if (schemeHandler && schemeHandler.parse) {
3774
4053
  schemeHandler.parse(parsed, options);
4054
+ if (schemeHandler === SCHEMES.urn && parsed.nid === undefined) {
4055
+ malformedSchemeSpecific = true;
4056
+ }
3775
4057
  }
3776
4058
  } else {
3777
4059
  parsed.error = parsed.error || "URI can not be parsed.";
3778
4060
  }
3779
- return { parsed, malformedAuthorityOrPort };
4061
+ return { parsed, malformedAuthorityOrPort, malformedPercentEncoding, malformedSchemeSpecific, malformedHost, malformedScheme };
3780
4062
  }
3781
4063
  function parse(uri, opts) {
3782
4064
  return parseWithStatus(uri, opts).parsed;
@@ -3785,20 +4067,28 @@ var require_fast_uri = __commonJS((exports, module) => {
3785
4067
  return normalizeStringWithStatus(uri, opts).normalized;
3786
4068
  }
3787
4069
  function normalizeStringWithStatus(uri, opts) {
3788
- const { parsed, malformedAuthorityOrPort } = parseWithStatus(uri, opts);
4070
+ const { parsed, malformedAuthorityOrPort, malformedPercentEncoding, malformedSchemeSpecific, malformedHost, malformedScheme } = parseWithStatus(uri, opts);
3789
4071
  return {
3790
- normalized: malformedAuthorityOrPort ? uri : serialize(parsed, opts),
3791
- malformedAuthorityOrPort
4072
+ normalized: malformedAuthorityOrPort || malformedPercentEncoding || malformedSchemeSpecific || malformedHost || malformedScheme ? uri : serialize(parsed, opts),
4073
+ malformedAuthorityOrPort,
4074
+ malformedPercentEncoding,
4075
+ malformedSchemeSpecific,
4076
+ malformedHost,
4077
+ malformedScheme
3792
4078
  };
3793
4079
  }
3794
4080
  function normalizeComparableURI(uri, opts) {
3795
- if (typeof uri === "string") {
3796
- const { normalized, malformedAuthorityOrPort } = normalizeStringWithStatus(uri, opts);
3797
- return malformedAuthorityOrPort ? undefined : normalized;
4081
+ if (typeof uri !== "string" && typeof uri !== "object") {
4082
+ return;
3798
4083
  }
3799
- if (typeof uri === "object") {
3800
- return serialize(uri, opts);
4084
+ let value;
4085
+ try {
4086
+ value = typeof uri === "string" ? uri : serialize(uri, opts);
4087
+ } catch {
4088
+ return;
3801
4089
  }
4090
+ const { normalized, malformedAuthorityOrPort, malformedPercentEncoding, malformedSchemeSpecific, malformedHost, malformedScheme } = normalizeStringWithStatus(value, opts);
4091
+ return malformedAuthorityOrPort || malformedPercentEncoding || malformedSchemeSpecific || malformedHost || malformedScheme ? undefined : normalized;
3802
4092
  }
3803
4093
  var fastUri = {
3804
4094
  SCHEMES,