@depup/js-yaml 5.4.3-depup.8 → 5.5.0-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/dist/js-yaml.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /*! js-yaml 5.4.3 https://github.com/nodeca/js-yaml @license MIT */
1
+ /*! js-yaml 5.5.0 https://github.com/nodeca/js-yaml @license MIT */
2
2
  //#region src/tag.ts
3
3
  /**
4
4
  * Returned by a scalar resolver when the source does not match its tag.
@@ -824,10 +824,8 @@ var Schema = class Schema {
824
824
  if (tag.matchByTagPrefix) prefix.sequence.push(tag);
825
825
  else exact.sequence[tag.tagName] = tag;
826
826
  break;
827
- case "mapping":
828
- if (tag.matchByTagPrefix) prefix.mapping.push(tag);
829
- else exact.mapping[tag.tagName] = tag;
830
- break;
827
+ case "mapping": if (tag.matchByTagPrefix) prefix.mapping.push(tag);
828
+ else exact.mapping[tag.tagName] = tag;
831
829
  }
832
830
  }
833
831
  const implicitScalarAnyFirstChar = implicitScalarTags.filter((tag) => tag.implicitFirstChars === null);
@@ -1415,16 +1413,17 @@ function getBlockValue(input, start, end, indent, chomping, folded) {
1415
1413
  }
1416
1414
  const content = line.slice(textIndent);
1417
1415
  const first = content.charCodeAt(0);
1418
- if (folded) if (first === 32 || first === 9) {
1419
- atMoreIndented = true;
1420
- result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines);
1421
- } else if (atMoreIndented) {
1422
- atMoreIndented = false;
1423
- result += "\n".repeat(emptyLines + 1);
1424
- } else if (emptyLines === 0) {
1425
- if (didReadContent) result += " ";
1426
- } else result += "\n".repeat(emptyLines);
1427
- else result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines);
1416
+ if (folded) {
1417
+ if (first === 32 || first === 9) {
1418
+ atMoreIndented = true;
1419
+ result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines);
1420
+ } else if (atMoreIndented) {
1421
+ atMoreIndented = false;
1422
+ result += "\n".repeat(emptyLines + 1);
1423
+ } else if (emptyLines === 0) {
1424
+ if (didReadContent) result += " ";
1425
+ } else result += "\n".repeat(emptyLines);
1426
+ } else result += "\n".repeat(didReadContent ? 1 + emptyLines : emptyLines);
1428
1427
  result += content;
1429
1428
  didReadContent = true;
1430
1429
  emptyLines = 0;
@@ -1458,24 +1457,69 @@ var DEFAULT_TAG_HANDLERS = Object.assign(Object.create(null), {
1458
1457
  "!": "!",
1459
1458
  "!!": "tag:yaml.org,2002:"
1460
1459
  });
1461
- function tagPercentEncode(source) {
1462
- return encodeURI(source).replace(/!/g, "%21");
1460
+ var TAG_SUFFIX_CHARS = "-#;/?:@&=+$_.~*'()";
1461
+ var TAG_URI_CHARS = TAG_SUFFIX_CHARS + "!,[]";
1462
+ var HEX = "0123456789ABCDEF";
1463
+ function percentByte(byte) {
1464
+ return "%" + HEX[byte >> 4] + HEX[byte & 15];
1465
+ }
1466
+ function tagPercentEncode(source, isSuffix) {
1467
+ const allowed = isSuffix ? TAG_SUFFIX_CHARS : TAG_URI_CHARS;
1468
+ let result = "";
1469
+ for (let index = 0; index < source.length; index++) {
1470
+ let ch = source.charCodeAt(index);
1471
+ if (ch >= 48 && ch <= 57 || ch >= 65 && ch <= 90 || ch >= 97 && ch <= 122 || allowed.includes(source[index])) {
1472
+ result += source[index];
1473
+ continue;
1474
+ }
1475
+ if (ch >= 55296 && ch <= 56319) ch = 65536 + ((ch & 1023) << 10) + (source.charCodeAt(++index) & 1023);
1476
+ if (ch < 128) result += percentByte(ch);
1477
+ else if (ch < 2048) result += percentByte(192 | ch >> 6) + percentByte(128 | ch & 63);
1478
+ else if (ch < 65536) result += percentByte(224 | ch >> 12) + percentByte(128 | ch >> 6 & 63) + percentByte(128 | ch & 63);
1479
+ else result += percentByte(240 | ch >> 18) + percentByte(128 | ch >> 12 & 63) + percentByte(128 | ch >> 6 & 63) + percentByte(128 | ch & 63);
1480
+ }
1481
+ return result;
1482
+ }
1483
+ function tagPercentDecode(source) {
1484
+ let result = "";
1485
+ let index = 0;
1486
+ while (index < source.length) {
1487
+ if (source.charCodeAt(index) !== 37) {
1488
+ result += source[index++];
1489
+ continue;
1490
+ }
1491
+ let ch = parseInt(source.slice(index + 1, index + 3), 16);
1492
+ index += 3;
1493
+ if (ch >= 192) {
1494
+ let remaining = ch < 224 ? 1 : ch < 240 ? 2 : 3;
1495
+ ch &= (1 << 6 - remaining) - 1;
1496
+ while (remaining-- > 0) {
1497
+ ch = ch << 6 | parseInt(source.slice(index + 1, index + 3), 16) & 63;
1498
+ index += 3;
1499
+ }
1500
+ }
1501
+ if (ch < 65536) result += String.fromCharCode(ch);
1502
+ else {
1503
+ ch -= 65536;
1504
+ result += String.fromCharCode(55296 | ch >> 10, 56320 | ch & 1023);
1505
+ }
1506
+ }
1507
+ return result;
1463
1508
  }
1464
1509
  function tagNameFull(rawTag, tagHandlers) {
1465
- if (rawTag.startsWith("!<") && rawTag.endsWith(">")) return decodeURIComponent(rawTag.slice(2, -1));
1510
+ if (rawTag.startsWith("!<") && rawTag.endsWith(">")) return tagPercentDecode(rawTag.slice(2, -1));
1466
1511
  const handleEnd = rawTag.indexOf("!", 1);
1467
1512
  const handle = handleEnd === -1 ? "!" : rawTag.slice(0, handleEnd + 1);
1468
- const prefix = tagHandlers?.[handle] ?? DEFAULT_TAG_HANDLERS[handle] ?? handle;
1469
- return decodeURIComponent(prefix) + decodeURIComponent(rawTag.slice(handle.length));
1513
+ return tagPercentDecode(tagHandlers?.[handle] ?? DEFAULT_TAG_HANDLERS[handle] ?? handle) + tagPercentDecode(rawTag.slice(handle.length));
1470
1514
  }
1471
1515
  function tagNameShort(fullTag) {
1472
1516
  let tag = fullTag;
1473
1517
  if (tag.charCodeAt(0) === 33) {
1474
1518
  tag = tag.slice(1);
1475
- return `!${tagPercentEncode(tag)}`;
1519
+ return `!${tagPercentEncode(tag, true)}`;
1476
1520
  }
1477
- if (tag.slice(0, 18) === "tag:yaml.org,2002:") return `!!${tagPercentEncode(tag.slice(18))}`;
1478
- return `!<${tagPercentEncode(tag)}>`;
1521
+ if (tag.slice(0, 18) === "tag:yaml.org,2002:") return `!!${tagPercentEncode(tag.slice(18), true)}`;
1522
+ return `!<${tagPercentEncode(tag, false)}>`;
1479
1523
  }
1480
1524
  //#endregion
1481
1525
  //#region src/parser/constructor.ts
@@ -1948,7 +1992,11 @@ function skipUntilLineEnd(state) {
1948
1992
  while (ch !== 0 && !isEol(ch)) ch = state.input.charCodeAt(++state.position);
1949
1993
  }
1950
1994
  function checkPrintable(state, start, end) {
1951
- if (PATTERN_NON_PRINTABLE.test(state.input.slice(start, end))) throwError(state, "the stream contains non-printable characters");
1995
+ const match = PATTERN_NON_PRINTABLE.exec(state.input.slice(start, end));
1996
+ if (match !== null) {
1997
+ state.position = start + match.index + match[0].length - 1;
1998
+ throwError(state, "the stream contains non-printable characters");
1999
+ }
1952
2000
  }
1953
2001
  function readTagProperty(state, props, inFlow) {
1954
2002
  if (state.input.charCodeAt(state.position) !== 33) return false;
@@ -1975,12 +2023,14 @@ function readTagProperty(state, props, inFlow) {
1975
2023
  state.position++;
1976
2024
  } else {
1977
2025
  while (ch !== 0 && !isWsOrEol(ch) && !(inFlow && isFlowIndicator(ch))) {
1978
- if (ch === 33) if (!isNamed) {
1979
- tagHandle = state.input.slice(suffixStart - 1, state.position + 1);
1980
- if (!PATTERN_TAG_HANDLE.test(tagHandle)) throwError(state, "named tag handle cannot contain such characters");
1981
- isNamed = true;
1982
- suffixStart = state.position + 1;
1983
- } else throwError(state, "tag suffix cannot contain exclamation marks");
2026
+ if (ch === 33) {
2027
+ if (!isNamed) {
2028
+ tagHandle = state.input.slice(suffixStart - 1, state.position + 1);
2029
+ if (!PATTERN_TAG_HANDLE.test(tagHandle)) throwError(state, "named tag handle cannot contain such characters");
2030
+ isNamed = true;
2031
+ suffixStart = state.position + 1;
2032
+ } else throwError(state, "tag suffix cannot contain exclamation marks");
2033
+ }
1984
2034
  ch = state.input.charCodeAt(++state.position);
1985
2035
  }
1986
2036
  tagName = state.input.slice(suffixStart, state.position);
@@ -2164,7 +2214,7 @@ function readBlockScalar(state, parentIndent, props) {
2164
2214
  function canStartPlainScalar(state, nodeContext) {
2165
2215
  const ch = state.input.charCodeAt(state.position);
2166
2216
  const inFlow = nodeContext === CONTEXT_FLOW_IN;
2167
- if (ch === 0 || isWsOrEol(ch) || ch === 35 || ch === 38 || ch === 42 || ch === 33 || ch === 124 || ch === 62 || ch === 39 || ch === 34 || ch === 37 || ch === 64 || ch === 96 || inFlow && isFlowIndicator(ch)) return false;
2217
+ if (ch === 0 || isWsOrEol(ch) || ch === 35 || ch === 38 || ch === 42 || ch === 33 || ch === 124 || ch === 62 || ch === 39 || ch === 34 || ch === 37 || ch === 64 || ch === 96 || isFlowIndicator(ch)) return false;
2168
2218
  if (ch === 63 || ch === 45) {
2169
2219
  const following = state.input.charCodeAt(state.position + 1);
2170
2220
  if (isWsOrEolOrEnd(following) || inFlow && isFlowIndicator(following)) return false;
@@ -2436,19 +2486,20 @@ function parseNode(state, parentIndent, nodeContext, allowToSeek, allowCompact,
2436
2486
  if (indentStatus === 1 || nodeContext === CONTEXT_BLOCK_OUT) {
2437
2487
  const flowIndent = nodeContext === CONTEXT_FLOW_IN || nodeContext === CONTEXT_FLOW_OUT ? parentIndent : parentIndent + 1;
2438
2488
  const blockIndent = state.position - state.lineStart;
2439
- if (indentStatus === 1) if (allowBlockCollections && (readBlockSequence(state, blockIndent, props) || readBlockMapping(state, blockIndent, flowIndent, props)) || readFlowCollection(state, flowIndent, props)) hasContent = true;
2440
- else {
2441
- const ch = state.input.charCodeAt(state.position);
2442
- if (propertyStart !== null && allowPropertyMapping && allowBlockStyles && !allowBlockCollections && ch !== 124 && ch !== 62) {
2443
- const fallbackState = snapshotState(state);
2444
- const propertyIndent = propertyStart.position - propertyStart.lineStart;
2445
- restoreState(state, propertyStart);
2446
- if (readBlockMapping(state, propertyIndent, flowIndent, emptyProperties()) && state.events[fallbackState.eventsLength]?.type === EVENT_ID.MAPPING) hasContent = true;
2447
- else restoreState(state, fallbackState);
2489
+ if (indentStatus === 1) {
2490
+ if (allowBlockCollections && (readBlockSequence(state, blockIndent, props) || readBlockMapping(state, blockIndent, flowIndent, props)) || readFlowCollection(state, flowIndent, props)) hasContent = true;
2491
+ else {
2492
+ const ch = state.input.charCodeAt(state.position);
2493
+ if (propertyStart !== null && allowPropertyMapping && allowBlockStyles && !allowBlockCollections && ch !== 124 && ch !== 62) {
2494
+ const fallbackState = snapshotState(state);
2495
+ const propertyIndent = propertyStart.position - propertyStart.lineStart;
2496
+ restoreState(state, propertyStart);
2497
+ if (readBlockMapping(state, propertyIndent, flowIndent, emptyProperties()) && state.events[fallbackState.eventsLength]?.type === EVENT_ID.MAPPING) hasContent = true;
2498
+ else restoreState(state, fallbackState);
2499
+ }
2500
+ if (!hasContent && (allowBlockScalars && readBlockScalar(state, flowIndent, props) || readSingleQuotedScalar(state, flowIndent, props) || readDoubleQuotedScalar(state, flowIndent, props) || readAlias(state, props) || readPlainScalar(state, flowIndent, nodeContext, props))) hasContent = true;
2448
2501
  }
2449
- if (!hasContent && (allowBlockScalars && readBlockScalar(state, flowIndent, props) || readSingleQuotedScalar(state, flowIndent, props) || readDoubleQuotedScalar(state, flowIndent, props) || readAlias(state, props) || readPlainScalar(state, flowIndent, nodeContext, props))) hasContent = true;
2450
- }
2451
- else if (indentStatus === 0) hasContent = allowBlockCollections && readBlockSequence(state, blockIndent, props);
2502
+ } else if (indentStatus === 0) hasContent = allowBlockCollections && readBlockSequence(state, blockIndent, props);
2452
2503
  }
2453
2504
  allowBlockScalars = allowBlockScalars && !hasContent;
2454
2505
  if (!hasContent && (props.anchorStart !== NO_RANGE$1 || props.tagStart !== NO_RANGE$1 || allowBlockScalars)) {
@@ -2795,20 +2846,18 @@ function visitNode(node, visitor, ctx) {
2795
2846
  isKey: false
2796
2847
  })) return true;
2797
2848
  break;
2798
- case "mapping":
2799
- for (const { key, value } of node.items) {
2800
- if (visitNode(key, visitor, {
2801
- depth,
2802
- parent: node,
2803
- isKey: true
2804
- })) return true;
2805
- if (visitNode(value, visitor, {
2806
- depth,
2807
- parent: node,
2808
- isKey: false
2809
- })) return true;
2810
- }
2811
- break;
2849
+ case "mapping": for (const { key, value } of node.items) {
2850
+ if (visitNode(key, visitor, {
2851
+ depth,
2852
+ parent: node,
2853
+ isKey: true
2854
+ })) return true;
2855
+ if (visitNode(value, visitor, {
2856
+ depth,
2857
+ parent: node,
2858
+ isKey: false
2859
+ })) return true;
2860
+ }
2812
2861
  }
2813
2862
  return false;
2814
2863
  }
@@ -3240,8 +3289,10 @@ function writeBlockMapping(state, level, node, compact) {
3240
3289
  const keyHasLineBreak = key.kind === "scalar" && key.value.indexOf("\n") !== -1;
3241
3290
  const keyIsTooLong = keyText.length > 1024 && /^[\s\S]{1025}/u.test(keyText);
3242
3291
  const explicitPair = keyIsBlock || keyHasLineBreak || keyIsTooLong;
3243
- if (explicitPair) if (keyText && CHAR_LINE_FEED === keyText.charCodeAt(0)) pairBuffer += "?";
3244
- else pairBuffer += "? ";
3292
+ if (explicitPair) {
3293
+ if (keyText && CHAR_LINE_FEED === keyText.charCodeAt(0)) pairBuffer += "?";
3294
+ else pairBuffer += "? ";
3295
+ }
3245
3296
  pairBuffer += keyText;
3246
3297
  if (explicitPair) pairBuffer += generateNextLine(state, level);
3247
3298
  const valueText = writeNode(state, level + 1, value, node, {
@@ -3277,12 +3328,15 @@ function writeNode(state, level, node, parent, ctx) {
3277
3328
  let body;
3278
3329
  let shouldPrintTag = node.tagged;
3279
3330
  const useBlockCollection = block && (node.kind === "mapping" || node.kind === "sequence") && node.style === COLLECTION_STYLE.BLOCK && node.items.length !== 0;
3280
- if (node.kind === "mapping") if (useBlockCollection) body = writeBlockMapping(state, level, node, compact);
3281
- else body = writeFlowMapping(state, level, node);
3282
- else if (node.kind === "sequence") if (useBlockCollection) if (state.seqNoIndent && !isblockseq && level > 0) body = writeBlockSequence(state, level - 1, node, compact);
3283
- else body = writeBlockSequence(state, level, node, compact);
3284
- else body = writeFlowSequence(state, level, node);
3285
- else {
3331
+ if (node.kind === "mapping") {
3332
+ if (useBlockCollection) body = writeBlockMapping(state, level, node, compact);
3333
+ else body = writeFlowMapping(state, level, node);
3334
+ } else if (node.kind === "sequence") {
3335
+ if (useBlockCollection) {
3336
+ if (state.seqNoIndent && !isblockseq && level > 0) body = writeBlockSequence(state, level - 1, node, compact);
3337
+ else body = writeBlockSequence(state, level, node, compact);
3338
+ } else body = writeFlowSequence(state, level, node);
3339
+ } else {
3286
3340
  const layout = scalarLayout(state, node, parent, level, iskey, !block);
3287
3341
  detectAllowedStyles(layout);
3288
3342
  for (const rule of state.scalarStyleRules) rule(layout);