summaryrefslogtreecommitdiff
path: root/node_modules/yaml/dist/nodes/Alias.js
diff options
context:
space:
mode:
authorMinteck <contact@minteck.org>2022-04-09 18:38:29 +0200
committerMinteck <contact@minteck.org>2022-04-09 18:38:29 +0200
commit457c93328f5b51b3fc0aa1600ce8eb8b45a5c2a9 (patch)
treea899daf11edb7ce6a99700e462a5740e013f5951 /node_modules/yaml/dist/nodes/Alias.js
downloadsnowjail-457c93328f5b51b3fc0aa1600ce8eb8b45a5c2a9.tar.gz
snowjail-457c93328f5b51b3fc0aa1600ce8eb8b45a5c2a9.tar.bz2
snowjail-457c93328f5b51b3fc0aa1600ce8eb8b45a5c2a9.zip
Snowjail v0.1
Diffstat (limited to 'node_modules/yaml/dist/nodes/Alias.js')
-rw-r--r--node_modules/yaml/dist/nodes/Alias.js96
1 files changed, 96 insertions, 0 deletions
diff --git a/node_modules/yaml/dist/nodes/Alias.js b/node_modules/yaml/dist/nodes/Alias.js
new file mode 100644
index 0000000..75853cf
--- /dev/null
+++ b/node_modules/yaml/dist/nodes/Alias.js
@@ -0,0 +1,96 @@
+'use strict';
+
+var anchors = require('../doc/anchors.js');
+var visit = require('../visit.js');
+var Node = require('./Node.js');
+
+class Alias extends Node.NodeBase {
+ constructor(source) {
+ super(Node.ALIAS);
+ this.source = source;
+ Object.defineProperty(this, 'tag', {
+ set() {
+ throw new Error('Alias nodes cannot have tags');
+ }
+ });
+ }
+ /**
+ * Resolve the value of this alias within `doc`, finding the last
+ * instance of the `source` anchor before this node.
+ */
+ resolve(doc) {
+ let found = undefined;
+ visit.visit(doc, {
+ Node: (_key, node) => {
+ if (node === this)
+ return visit.visit.BREAK;
+ if (node.anchor === this.source)
+ found = node;
+ }
+ });
+ return found;
+ }
+ toJSON(_arg, ctx) {
+ if (!ctx)
+ return { source: this.source };
+ const { anchors, doc, maxAliasCount } = ctx;
+ const source = this.resolve(doc);
+ if (!source) {
+ const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
+ throw new ReferenceError(msg);
+ }
+ const data = anchors.get(source);
+ /* istanbul ignore if */
+ if (!data || data.res === undefined) {
+ const msg = 'This should not happen: Alias anchor was not resolved?';
+ throw new ReferenceError(msg);
+ }
+ if (maxAliasCount >= 0) {
+ data.count += 1;
+ if (data.aliasCount === 0)
+ data.aliasCount = getAliasCount(doc, source, anchors);
+ if (data.count * data.aliasCount > maxAliasCount) {
+ const msg = 'Excessive alias count indicates a resource exhaustion attack';
+ throw new ReferenceError(msg);
+ }
+ }
+ return data.res;
+ }
+ toString(ctx, _onComment, _onChompKeep) {
+ const src = `*${this.source}`;
+ if (ctx) {
+ anchors.anchorIsValid(this.source);
+ if (ctx.options.verifyAliasOrder && !ctx.anchors.has(this.source)) {
+ const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
+ throw new Error(msg);
+ }
+ if (ctx.implicitKey)
+ return `${src} `;
+ }
+ return src;
+ }
+}
+function getAliasCount(doc, node, anchors) {
+ if (Node.isAlias(node)) {
+ const source = node.resolve(doc);
+ const anchor = anchors && source && anchors.get(source);
+ return anchor ? anchor.count * anchor.aliasCount : 0;
+ }
+ else if (Node.isCollection(node)) {
+ let count = 0;
+ for (const item of node.items) {
+ const c = getAliasCount(doc, item, anchors);
+ if (c > count)
+ count = c;
+ }
+ return count;
+ }
+ else if (Node.isPair(node)) {
+ const kc = getAliasCount(doc, node.key, anchors);
+ const vc = getAliasCount(doc, node.value, anchors);
+ return Math.max(kc, vc);
+ }
+ return 1;
+}
+
+exports.Alias = Alias;