Dashboard sipadu mbip
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = void 0;
  6. var _constants = require("../constants");
  7. var _errors = require("../errors");
  8. var _toJSON = _interopRequireDefault(require("../toJSON"));
  9. var _Collection = _interopRequireDefault(require("./Collection"));
  10. var _Node = _interopRequireDefault(require("./Node"));
  11. var _Pair = _interopRequireDefault(require("./Pair"));
  12. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  13. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  14. const getAliasCount = (node, anchors) => {
  15. if (node instanceof Alias) {
  16. const anchor = anchors.find(a => a.node === node.source);
  17. return anchor.count * anchor.aliasCount;
  18. } else if (node instanceof _Collection.default) {
  19. let count = 0;
  20. for (const item of node.items) {
  21. const c = getAliasCount(item, anchors);
  22. if (c > count) count = c;
  23. }
  24. return count;
  25. } else if (node instanceof _Pair.default) {
  26. const kc = getAliasCount(node.key, anchors);
  27. const vc = getAliasCount(node.value, anchors);
  28. return Math.max(kc, vc);
  29. }
  30. return 1;
  31. };
  32. class Alias extends _Node.default {
  33. static stringify({
  34. range,
  35. source
  36. }, {
  37. anchors,
  38. doc,
  39. implicitKey,
  40. inStringifyKey
  41. }) {
  42. let anchor = Object.keys(anchors).find(a => anchors[a] === source);
  43. if (!anchor && inStringifyKey) anchor = doc.anchors.getName(source) || doc.anchors.newName();
  44. if (anchor) return `*${anchor}${implicitKey ? ' ' : ''}`;
  45. const msg = doc.anchors.getName(source) ? 'Alias node must be after source node' : 'Source node not found for alias node';
  46. throw new Error(`${msg} [${range}]`);
  47. }
  48. constructor(source) {
  49. super();
  50. this.source = source;
  51. this.type = _constants.Type.ALIAS;
  52. }
  53. set tag(t) {
  54. throw new Error('Alias nodes cannot have tags');
  55. }
  56. toJSON(arg, ctx) {
  57. if (!ctx) return (0, _toJSON.default)(this.source, arg, ctx);
  58. const {
  59. anchors,
  60. maxAliasCount
  61. } = ctx;
  62. const anchor = anchors.find(a => a.node === this.source);
  63. if (!anchor || anchor.res === undefined) {
  64. const msg = 'This should not happen: Alias anchor was not resolved?';
  65. if (this.cstNode) throw new _errors.YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg);
  66. }
  67. if (maxAliasCount >= 0) {
  68. anchor.count += 1;
  69. if (anchor.aliasCount === 0) anchor.aliasCount = getAliasCount(this.source, anchors);
  70. if (anchor.count * anchor.aliasCount > maxAliasCount) {
  71. const msg = 'Excessive alias count indicates a resource exhaustion attack';
  72. if (this.cstNode) throw new _errors.YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg);
  73. }
  74. }
  75. return anchor.res;
  76. } // Only called when stringifying an alias mapping key while constructing
  77. // Object output.
  78. toString(ctx) {
  79. return Alias.stringify(this, ctx);
  80. }
  81. }
  82. exports.default = Alias;
  83. _defineProperty(Alias, "default", true);