diff --git a/dist/post_run/index.js b/dist/post_run/index.js index a130721..28547fb 100644 --- a/dist/post_run/index.js +++ b/dist/post_run/index.js @@ -101614,8 +101614,10 @@ class Composer { } } if (afterDoc) { - Array.prototype.push.apply(doc.errors, this.errors); - Array.prototype.push.apply(doc.warnings, this.warnings); + for (let i = 0; i < this.errors.length; ++i) + doc.errors.push(this.errors[i]); + for (let i = 0; i < this.warnings.length; ++i) + doc.warnings.push(this.warnings[i]); } else { doc.errors = this.errors; @@ -102547,7 +102549,7 @@ function doubleQuotedValue(source, onError) { next = source[++i + 1]; } else if (next === 'x' || next === 'u' || next === 'U') { - const length = { x: 2, u: 4, U: 8 }[next]; + const length = next === 'x' ? 2 : next === 'u' ? 4 : 8; res += parseCharCode(source, i + 1, length, onError); i += length; } @@ -102617,12 +102619,14 @@ function parseCharCode(source, offset, length, onError) { const cc = source.substr(offset, length); const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc); const code = ok ? parseInt(cc, 16) : NaN; - if (isNaN(code)) { + try { + return String.fromCodePoint(code); + } + catch { const raw = source.substr(offset - 2, length + 2); onError(offset - 2, 'BAD_DQ_ESCAPE', `Invalid escape sequence ${raw}`); return raw; } - return String.fromCodePoint(code); } exports.resolveFlowScalar = resolveFlowScalar; @@ -103874,6 +103878,8 @@ class Alias extends Node.NodeBase { * instance of the `source` anchor before this node. */ resolve(doc, ctx) { + if (ctx?.maxAliasCount === 0) + throw new ReferenceError('Alias resolution is disabled'); let nodes; if (ctx?.aliasResolveCache) { nodes = ctx.aliasResolveCache; @@ -105561,7 +105567,7 @@ class Lexer { const n = (yield* this.pushCount(1)) + (yield* this.pushSpaces(true)); this.indentNext = this.indentValue + 1; this.indentValue += n; - return yield* this.parseBlockStart(); + return 'block-start'; } return 'doc'; } @@ -105882,32 +105888,36 @@ class Lexer { return 0; } *pushIndicators() { - switch (this.charAt(0)) { - case '!': - return ((yield* this.pushTag()) + - (yield* this.pushSpaces(true)) + - (yield* this.pushIndicators())); - case '&': - return ((yield* this.pushUntil(isNotAnchorChar)) + - (yield* this.pushSpaces(true)) + - (yield* this.pushIndicators())); - case '-': // this is an error - case '?': // this is an error outside flow collections - case ':': { - const inFlow = this.flowLevel > 0; - const ch1 = this.charAt(1); - if (isEmpty(ch1) || (inFlow && flowIndicatorChars.has(ch1))) { - if (!inFlow) - this.indentNext = this.indentValue + 1; - else if (this.flowKey) - this.flowKey = false; - return ((yield* this.pushCount(1)) + - (yield* this.pushSpaces(true)) + - (yield* this.pushIndicators())); + let n = 0; + loop: while (true) { + switch (this.charAt(0)) { + case '!': + n += yield* this.pushTag(); + n += yield* this.pushSpaces(true); + continue loop; + case '&': + n += yield* this.pushUntil(isNotAnchorChar); + n += yield* this.pushSpaces(true); + continue loop; + case '-': // this is an error + case '?': // this is an error outside flow collections + case ':': { + const inFlow = this.flowLevel > 0; + const ch1 = this.charAt(1); + if (isEmpty(ch1) || (inFlow && flowIndicatorChars.has(ch1))) { + if (!inFlow) + this.indentNext = this.indentValue + 1; + else if (this.flowKey) + this.flowKey = false; + n += yield* this.pushCount(1); + n += yield* this.pushSpaces(true); + continue loop; + } } } + break loop; } - return 0; + return n; } *pushTag() { if (this.charAt(1) === '<') { @@ -106095,6 +106105,14 @@ function getFirstKeyStartProps(prev) { } return prev.splice(i, prev.length); } +function arrayPushArray(target, source) { + // May exhaust call stack with large `source` array + if (source.length < 1e5) + Array.prototype.push.apply(target, source); + else + for (let i = 0; i < source.length; ++i) + target.push(source[i]); +} function fixFlowSeqItems(fc) { if (fc.start.type === 'flow-seq-start') { for (const it of fc.items) { @@ -106107,12 +106125,12 @@ function fixFlowSeqItems(fc) { delete it.key; if (isFlowToken(it.value)) { if (it.value.end) - Array.prototype.push.apply(it.value.end, it.sep); + arrayPushArray(it.value.end, it.sep); else it.value.end = it.sep; } else - Array.prototype.push.apply(it.start, it.sep); + arrayPushArray(it.start, it.sep); delete it.sep; } } @@ -106532,7 +106550,7 @@ class Parser { const prev = map.items[map.items.length - 2]; const end = prev?.value?.end; if (Array.isArray(end)) { - Array.prototype.push.apply(end, it.start); + arrayPushArray(end, it.start); end.push(this.sourceToken); map.items.pop(); return; @@ -106747,7 +106765,7 @@ class Parser { const prev = seq.items[seq.items.length - 2]; const end = prev?.value?.end; if (Array.isArray(end)) { - Array.prototype.push.apply(end, it.start); + arrayPushArray(end, it.start); end.push(this.sourceToken); seq.items.pop(); return; @@ -107901,18 +107919,18 @@ const isMergeKey = (ctx, key) => (merge.identify(key) || merge.identify(key.value))) && ctx?.doc.schema.tags.some(tag => tag.tag === merge.tag && tag.default); function addMergeToJSMap(ctx, map, value) { - value = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value; - if (identity.isSeq(value)) - for (const it of value.items) + const source = resolveAliasValue(ctx, value); + if (identity.isSeq(source)) + for (const it of source.items) mergeValue(ctx, map, it); - else if (Array.isArray(value)) - for (const it of value) + else if (Array.isArray(source)) + for (const it of source) mergeValue(ctx, map, it); else - mergeValue(ctx, map, value); + mergeValue(ctx, map, source); } function mergeValue(ctx, map, value) { - const source = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value; + const source = resolveAliasValue(ctx, value); if (!identity.isMap(source)) throw new Error('Merge sources must be maps or map aliases'); const srcMap = source.toJSON(null, ctx, Map); @@ -107935,6 +107953,9 @@ function mergeValue(ctx, map, value) { } return map; } +function resolveAliasValue(ctx, value) { + return ctx && identity.isAlias(value) ? value.resolve(ctx.doc, ctx) : value; +} exports.addMergeToJSMap = addMergeToJSMap; exports.isMergeKey = isMergeKey; @@ -108989,7 +109010,8 @@ function stringifyNumber({ format, minFractionDigits, tag, value }) { if (!format && minFractionDigits && (!tag || tag === 'tag:yaml.org,2002:float') && - /^\d/.test(n)) { + /^-?\d/.test(n) && + !n.includes('e')) { let i = n.indexOf('.'); if (i < 0) { i = n.length; diff --git a/dist/run/index.js b/dist/run/index.js index 96b5cc9..cfaeba7 100644 --- a/dist/run/index.js +++ b/dist/run/index.js @@ -101614,8 +101614,10 @@ class Composer { } } if (afterDoc) { - Array.prototype.push.apply(doc.errors, this.errors); - Array.prototype.push.apply(doc.warnings, this.warnings); + for (let i = 0; i < this.errors.length; ++i) + doc.errors.push(this.errors[i]); + for (let i = 0; i < this.warnings.length; ++i) + doc.warnings.push(this.warnings[i]); } else { doc.errors = this.errors; @@ -102547,7 +102549,7 @@ function doubleQuotedValue(source, onError) { next = source[++i + 1]; } else if (next === 'x' || next === 'u' || next === 'U') { - const length = { x: 2, u: 4, U: 8 }[next]; + const length = next === 'x' ? 2 : next === 'u' ? 4 : 8; res += parseCharCode(source, i + 1, length, onError); i += length; } @@ -102617,12 +102619,14 @@ function parseCharCode(source, offset, length, onError) { const cc = source.substr(offset, length); const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc); const code = ok ? parseInt(cc, 16) : NaN; - if (isNaN(code)) { + try { + return String.fromCodePoint(code); + } + catch { const raw = source.substr(offset - 2, length + 2); onError(offset - 2, 'BAD_DQ_ESCAPE', `Invalid escape sequence ${raw}`); return raw; } - return String.fromCodePoint(code); } exports.resolveFlowScalar = resolveFlowScalar; @@ -103874,6 +103878,8 @@ class Alias extends Node.NodeBase { * instance of the `source` anchor before this node. */ resolve(doc, ctx) { + if (ctx?.maxAliasCount === 0) + throw new ReferenceError('Alias resolution is disabled'); let nodes; if (ctx?.aliasResolveCache) { nodes = ctx.aliasResolveCache; @@ -105561,7 +105567,7 @@ class Lexer { const n = (yield* this.pushCount(1)) + (yield* this.pushSpaces(true)); this.indentNext = this.indentValue + 1; this.indentValue += n; - return yield* this.parseBlockStart(); + return 'block-start'; } return 'doc'; } @@ -105882,32 +105888,36 @@ class Lexer { return 0; } *pushIndicators() { - switch (this.charAt(0)) { - case '!': - return ((yield* this.pushTag()) + - (yield* this.pushSpaces(true)) + - (yield* this.pushIndicators())); - case '&': - return ((yield* this.pushUntil(isNotAnchorChar)) + - (yield* this.pushSpaces(true)) + - (yield* this.pushIndicators())); - case '-': // this is an error - case '?': // this is an error outside flow collections - case ':': { - const inFlow = this.flowLevel > 0; - const ch1 = this.charAt(1); - if (isEmpty(ch1) || (inFlow && flowIndicatorChars.has(ch1))) { - if (!inFlow) - this.indentNext = this.indentValue + 1; - else if (this.flowKey) - this.flowKey = false; - return ((yield* this.pushCount(1)) + - (yield* this.pushSpaces(true)) + - (yield* this.pushIndicators())); + let n = 0; + loop: while (true) { + switch (this.charAt(0)) { + case '!': + n += yield* this.pushTag(); + n += yield* this.pushSpaces(true); + continue loop; + case '&': + n += yield* this.pushUntil(isNotAnchorChar); + n += yield* this.pushSpaces(true); + continue loop; + case '-': // this is an error + case '?': // this is an error outside flow collections + case ':': { + const inFlow = this.flowLevel > 0; + const ch1 = this.charAt(1); + if (isEmpty(ch1) || (inFlow && flowIndicatorChars.has(ch1))) { + if (!inFlow) + this.indentNext = this.indentValue + 1; + else if (this.flowKey) + this.flowKey = false; + n += yield* this.pushCount(1); + n += yield* this.pushSpaces(true); + continue loop; + } } } + break loop; } - return 0; + return n; } *pushTag() { if (this.charAt(1) === '<') { @@ -106095,6 +106105,14 @@ function getFirstKeyStartProps(prev) { } return prev.splice(i, prev.length); } +function arrayPushArray(target, source) { + // May exhaust call stack with large `source` array + if (source.length < 1e5) + Array.prototype.push.apply(target, source); + else + for (let i = 0; i < source.length; ++i) + target.push(source[i]); +} function fixFlowSeqItems(fc) { if (fc.start.type === 'flow-seq-start') { for (const it of fc.items) { @@ -106107,12 +106125,12 @@ function fixFlowSeqItems(fc) { delete it.key; if (isFlowToken(it.value)) { if (it.value.end) - Array.prototype.push.apply(it.value.end, it.sep); + arrayPushArray(it.value.end, it.sep); else it.value.end = it.sep; } else - Array.prototype.push.apply(it.start, it.sep); + arrayPushArray(it.start, it.sep); delete it.sep; } } @@ -106532,7 +106550,7 @@ class Parser { const prev = map.items[map.items.length - 2]; const end = prev?.value?.end; if (Array.isArray(end)) { - Array.prototype.push.apply(end, it.start); + arrayPushArray(end, it.start); end.push(this.sourceToken); map.items.pop(); return; @@ -106747,7 +106765,7 @@ class Parser { const prev = seq.items[seq.items.length - 2]; const end = prev?.value?.end; if (Array.isArray(end)) { - Array.prototype.push.apply(end, it.start); + arrayPushArray(end, it.start); end.push(this.sourceToken); seq.items.pop(); return; @@ -107901,18 +107919,18 @@ const isMergeKey = (ctx, key) => (merge.identify(key) || merge.identify(key.value))) && ctx?.doc.schema.tags.some(tag => tag.tag === merge.tag && tag.default); function addMergeToJSMap(ctx, map, value) { - value = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value; - if (identity.isSeq(value)) - for (const it of value.items) + const source = resolveAliasValue(ctx, value); + if (identity.isSeq(source)) + for (const it of source.items) mergeValue(ctx, map, it); - else if (Array.isArray(value)) - for (const it of value) + else if (Array.isArray(source)) + for (const it of source) mergeValue(ctx, map, it); else - mergeValue(ctx, map, value); + mergeValue(ctx, map, source); } function mergeValue(ctx, map, value) { - const source = ctx && identity.isAlias(value) ? value.resolve(ctx.doc) : value; + const source = resolveAliasValue(ctx, value); if (!identity.isMap(source)) throw new Error('Merge sources must be maps or map aliases'); const srcMap = source.toJSON(null, ctx, Map); @@ -107935,6 +107953,9 @@ function mergeValue(ctx, map, value) { } return map; } +function resolveAliasValue(ctx, value) { + return ctx && identity.isAlias(value) ? value.resolve(ctx.doc, ctx) : value; +} exports.addMergeToJSMap = addMergeToJSMap; exports.isMergeKey = isMergeKey; @@ -108989,7 +109010,8 @@ function stringifyNumber({ format, minFractionDigits, tag, value }) { if (!format && minFractionDigits && (!tag || tag === 'tag:yaml.org,2002:float') && - /^\d/.test(n)) { + /^-?\d/.test(n) && + !n.includes('e')) { let i = n.indexOf('.'); if (i < 0) { i = n.length; diff --git a/package-lock.json b/package-lock.json index 60e0432..14fd217 100644 --- a/package-lock.json +++ b/package-lock.json @@ -21,8 +21,8 @@ "@types/tmp": "^0.2.6", "@types/which": "^3.0.4", "tmp": "^0.2.5", - "which": "^6.0.1", - "yaml": "^2.8.3" + "which": "^7.0.0", + "yaml": "^2.9.0" }, "devDependencies": { "@eslint/compat": "^2.0.5", @@ -4239,9 +4239,9 @@ } }, "node_modules/which": { - "version": "6.0.1", - "resolved": "https://registry.npmjs.org/which/-/which-6.0.1.tgz", - "integrity": "sha512-oGLe46MIrCRqX7ytPUf66EAYvdeMIZYn3WaocqqKZAxrBpkqHfL/qvTyJ/bTk5+AqHCjXmrv3CEWgy368zhRUg==", + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/which/-/which-7.0.0.tgz", + "integrity": "sha512-RancgH2dmbLdHl6LRhEqvklWMgl/Hdnun0Y90KhBOLkMefg8Qa7/Zel8Sm+8HEcP6DEjzsWzpkuBQEZok58isA==", "license": "ISC", "dependencies": { "isexe": "^4.0.0" @@ -4250,7 +4250,7 @@ "node-which": "bin/which.js" }, "engines": { - "node": "^20.17.0 || >=22.9.0" + "node": "^22.22.2 || ^24.15.0 || >=26.0.0" } }, "node_modules/which-boxed-primitive": { @@ -4372,9 +4372,9 @@ } }, "node_modules/yaml": { - "version": "2.8.3", - "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.8.3.tgz", - "integrity": "sha512-AvbaCLOO2Otw/lW5bmh9d/WEdcDFdQp2Z2ZUH3pX9U2ihyUY0nvLv7J6TrWowklRGPYbB/IuIMfYgxaCPg5Bpg==", + "version": "2.9.0", + "resolved": "https://registry.npmjs.org/yaml/-/yaml-2.9.0.tgz", + "integrity": "sha512-2AvhNX3mb8zd6Zy7INTtSpl1F15HW6Wnqj0srWlkKLcpYl/gMIMJiyuGq2KeI2YFxUPjdlB+3Lc10seMLtL4cA==", "license": "ISC", "bin": { "yaml": "bin.mjs" diff --git a/package.json b/package.json index a5d8dc9..39e366c 100644 --- a/package.json +++ b/package.json @@ -39,8 +39,8 @@ "@types/tmp": "^0.2.6", "@types/which": "^3.0.4", "tmp": "^0.2.5", - "which": "^6.0.1", - "yaml": "^2.8.3" + "which": "^7.0.0", + "yaml": "^2.9.0" }, "devDependencies": { "@eslint/compat": "^2.0.5",