diff options
Diffstat (limited to 'node_modules/yaml/browser/dist')
17 files changed, 112 insertions, 60 deletions
diff --git a/node_modules/yaml/browser/dist/compose/compose-collection.js b/node_modules/yaml/browser/dist/compose/compose-collection.js index 8d4507f3..b80fba27 100644 --- a/node_modules/yaml/browser/dist/compose/compose-collection.js +++ b/node_modules/yaml/browser/dist/compose/compose-collection.js @@ -23,10 +23,23 @@ function resolveCollection(CN, ctx, token, onError, tagName, tag) { coll.tag = tagName; return coll; } -function composeCollection(CN, ctx, token, tagToken, onError) { +function composeCollection(CN, ctx, token, props, onError) { + const tagToken = props.tag; const tagName = !tagToken ? null : ctx.directives.tagName(tagToken.source, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg)); + if (token.type === 'block-seq') { + const { anchor, newlineAfterProp: nl } = props; + const lastProp = anchor && tagToken + ? anchor.offset > tagToken.offset + ? anchor + : tagToken + : (anchor ?? tagToken); + if (lastProp && (!nl || nl.offset < lastProp.offset)) { + const message = 'Missing newline after block sequence props'; + onError(lastProp, 'MISSING_CHAR', message); + } + } const expType = token.type === 'block-map' ? 'map' : token.type === 'block-seq' @@ -40,8 +53,7 @@ function composeCollection(CN, ctx, token, tagToken, onError) { !tagName || tagName === '!' || (tagName === YAMLMap.tagName && expType === 'map') || - (tagName === YAMLSeq.tagName && expType === 'seq') || - !expType) { + (tagName === YAMLSeq.tagName && expType === 'seq')) { return resolveCollection(CN, ctx, token, onError, tagName); } let tag = ctx.schema.tags.find(t => t.tag === tagName && t.collection === expType); diff --git a/node_modules/yaml/browser/dist/compose/compose-doc.js b/node_modules/yaml/browser/dist/compose/compose-doc.js index d36c380b..95f97246 100644 --- a/node_modules/yaml/browser/dist/compose/compose-doc.js +++ b/node_modules/yaml/browser/dist/compose/compose-doc.js @@ -17,6 +17,7 @@ function composeDoc(options, directives, { offset, start, value, end }, onError) next: value ?? end?.[0], offset, onError, + parentIndent: 0, startOnNewline: true }); if (props.found) { diff --git a/node_modules/yaml/browser/dist/compose/compose-node.js b/node_modules/yaml/browser/dist/compose/compose-node.js index 39d98e36..611c4a55 100644 --- a/node_modules/yaml/browser/dist/compose/compose-node.js +++ b/node_modules/yaml/browser/dist/compose/compose-node.js @@ -26,7 +26,7 @@ function composeNode(ctx, token, props, onError) { case 'block-map': case 'block-seq': case 'flow-collection': - node = composeCollection(CN, ctx, token, tag, onError); + node = composeCollection(CN, ctx, token, props, onError); if (anchor) node.anchor = anchor.source.substring(1); break; diff --git a/node_modules/yaml/browser/dist/compose/compose-scalar.js b/node_modules/yaml/browser/dist/compose/compose-scalar.js index fb4447d8..98e8cd03 100644 --- a/node_modules/yaml/browser/dist/compose/compose-scalar.js +++ b/node_modules/yaml/browser/dist/compose/compose-scalar.js @@ -5,7 +5,7 @@ import { resolveFlowScalar } from './resolve-flow-scalar.js'; function composeScalar(ctx, token, tagToken, onError) { const { value, type, comment, range } = token.type === 'block-scalar' - ? resolveBlockScalar(token, ctx.options.strict, onError) + ? resolveBlockScalar(ctx, token, onError) : resolveFlowScalar(token, ctx.options.strict, onError); const tagName = tagToken ? ctx.directives.tagName(tagToken.source, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg)) diff --git a/node_modules/yaml/browser/dist/compose/resolve-block-map.js b/node_modules/yaml/browser/dist/compose/resolve-block-map.js index 679b3dee..1413a880 100644 --- a/node_modules/yaml/browser/dist/compose/resolve-block-map.js +++ b/node_modules/yaml/browser/dist/compose/resolve-block-map.js @@ -21,6 +21,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError, ta next: key ?? sep?.[0], offset, onError, + parentIndent: bm.indent, startOnNewline: true }); const implicitKey = !keyProps.found; @@ -41,7 +42,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError, ta } continue; } - if (keyProps.hasNewlineAfterProp || containsNewline(key)) { + if (keyProps.newlineAfterProp || containsNewline(key)) { onError(key ?? start[start.length - 1], 'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line'); } } @@ -63,6 +64,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError, ta next: value, offset: keyNode.range[2], onError, + parentIndent: bm.indent, startOnNewline: !key || key.type === 'block-scalar' }); offset = valueProps.end; diff --git a/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js b/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js index 592d8075..9b7b7b55 100644 --- a/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js +++ b/node_modules/yaml/browser/dist/compose/resolve-block-scalar.js @@ -1,8 +1,8 @@ import { Scalar } from '../nodes/Scalar.js'; -function resolveBlockScalar(scalar, strict, onError) { +function resolveBlockScalar(ctx, scalar, onError) { const start = scalar.offset; - const header = parseBlockScalarHeader(scalar, strict, onError); + const header = parseBlockScalarHeader(scalar, ctx.options.strict, onError); if (!header) return { value: '', type: null, comment: '', range: [start, start, start] }; const type = header.mode === '>' ? Scalar.BLOCK_FOLDED : Scalar.BLOCK_LITERAL; @@ -44,6 +44,10 @@ function resolveBlockScalar(scalar, strict, onError) { if (header.indent === 0) trimIndent = indent.length; contentStart = i; + if (trimIndent === 0 && !ctx.atRoot) { + const message = 'Block scalar values in collections must be indented'; + onError(offset, 'BAD_INDENT', message); + } break; } offset += indent.length + content.length + 1; diff --git a/node_modules/yaml/browser/dist/compose/resolve-block-seq.js b/node_modules/yaml/browser/dist/compose/resolve-block-seq.js index 3241ca79..9e69e09d 100644 --- a/node_modules/yaml/browser/dist/compose/resolve-block-seq.js +++ b/node_modules/yaml/browser/dist/compose/resolve-block-seq.js @@ -15,6 +15,7 @@ function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError, ta next: value, offset, onError, + parentIndent: bs.indent, startOnNewline: true }); if (!props.found) { diff --git a/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js b/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js index fdf929a0..bbf18a82 100644 --- a/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js +++ b/node_modules/yaml/browser/dist/compose/resolve-flow-collection.js @@ -28,6 +28,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr next: key ?? sep?.[0], offset, onError, + parentIndent: fc.indent, startOnNewline: false }); if (!props.found) { @@ -109,6 +110,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr next: value, offset: keyNode.range[2], onError, + parentIndent: fc.indent, startOnNewline: false }); if (valueProps.found) { diff --git a/node_modules/yaml/browser/dist/compose/resolve-props.js b/node_modules/yaml/browser/dist/compose/resolve-props.js index ab30f56f..dd6ce6cc 100644 --- a/node_modules/yaml/browser/dist/compose/resolve-props.js +++ b/node_modules/yaml/browser/dist/compose/resolve-props.js @@ -1,14 +1,15 @@ -function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnNewline }) { +function resolveProps(tokens, { flow, indicator, next, offset, onError, parentIndent, startOnNewline }) { let spaceBefore = false; let atNewline = startOnNewline; let hasSpace = startOnNewline; let comment = ''; let commentSep = ''; let hasNewline = false; - let hasNewlineAfterProp = false; let reqSpace = false; + let tab = null; let anchor = null; let tag = null; + let newlineAfterProp = null; let comma = null; let found = null; let start = null; @@ -20,16 +21,22 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN onError(token.offset, 'MISSING_CHAR', 'Tags and anchors must be separated from the next token by white space'); reqSpace = false; } + if (tab) { + if (atNewline && token.type !== 'comment' && token.type !== 'newline') { + onError(tab, 'TAB_AS_INDENT', 'Tabs are not allowed as indentation'); + } + tab = null; + } switch (token.type) { case 'space': // At the doc level, tabs at line start may be parsed // as leading white space rather than indentation. // In a flow collection, only the parser handles indent. if (!flow && - atNewline && - indicator !== 'doc-start' && - token.source[0] === '\t') - onError(token, 'TAB_AS_INDENT', 'Tabs are not allowed as indentation'); + (indicator !== 'doc-start' || next?.type !== 'flow-collection') && + token.source.includes('\t')) { + tab = token; + } hasSpace = true; break; case 'comment': { @@ -56,7 +63,7 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN atNewline = true; hasNewline = true; if (anchor || tag) - hasNewlineAfterProp = true; + newlineAfterProp = token; hasSpace = true; break; case 'anchor': @@ -89,7 +96,8 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN if (found) onError(token, 'UNEXPECTED_TOKEN', `Unexpected ${token.source} in ${flow ?? 'collection'}`); found = token; - atNewline = false; + atNewline = + indicator === 'seq-item-ind' || indicator === 'explicit-key-ind'; hasSpace = false; break; case 'comma': @@ -115,17 +123,23 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, startOnN next.type !== 'space' && next.type !== 'newline' && next.type !== 'comma' && - (next.type !== 'scalar' || next.source !== '')) + (next.type !== 'scalar' || next.source !== '')) { onError(next.offset, 'MISSING_CHAR', 'Tags and anchors must be separated from the next token by white space'); + } + if (tab && + ((atNewline && tab.indent <= parentIndent) || + next?.type === 'block-map' || + next?.type === 'block-seq')) + onError(tab, 'TAB_AS_INDENT', 'Tabs are not allowed as indentation'); return { comma, found, spaceBefore, comment, hasNewline, - hasNewlineAfterProp, anchor, tag, + newlineAfterProp, end, start: start ?? end }; diff --git a/node_modules/yaml/browser/dist/nodes/Collection.js b/node_modules/yaml/browser/dist/nodes/Collection.js index a5f89bec..0ebdeda0 100644 --- a/node_modules/yaml/browser/dist/nodes/Collection.js +++ b/node_modules/yaml/browser/dist/nodes/Collection.js @@ -143,6 +143,5 @@ class Collection extends NodeBase { } } } -Collection.maxFlowStringSingleLineLength = 60; export { Collection, collectionFromPath, isEmptyPath }; diff --git a/node_modules/yaml/browser/dist/parse/cst-scalar.js b/node_modules/yaml/browser/dist/parse/cst-scalar.js index d4def990..29ab354b 100644 --- a/node_modules/yaml/browser/dist/parse/cst-scalar.js +++ b/node_modules/yaml/browser/dist/parse/cst-scalar.js @@ -18,7 +18,7 @@ function resolveAsScalar(token, strict = true, onError) { case 'double-quoted-scalar': return resolveFlowScalar(token, strict, _onError); case 'block-scalar': - return resolveBlockScalar(token, strict, _onError); + return resolveBlockScalar({ options: { strict } }, token, _onError); } } return null; diff --git a/node_modules/yaml/browser/dist/parse/lexer.js b/node_modules/yaml/browser/dist/parse/lexer.js index 20fe13c2..fbab236e 100644 --- a/node_modules/yaml/browser/dist/parse/lexer.js +++ b/node_modules/yaml/browser/dist/parse/lexer.js @@ -79,11 +79,11 @@ function isEmpty(ch) { return false; } } -const hexDigits = '0123456789ABCDEFabcdef'.split(''); -const tagChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()".split(''); -const invalidFlowScalarChars = ',[]{}'.split(''); -const invalidAnchorChars = ' ,[]{}\n\r\t'.split(''); -const isNotAnchorChar = (ch) => !ch || invalidAnchorChars.includes(ch); +const hexDigits = new Set('0123456789ABCDEFabcdef'); +const tagChars = new Set("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-#;/?:@&=+$_.!~*'()"); +const flowIndicatorChars = new Set(',[]{}'); +const invalidAnchorChars = new Set(' ,[]{}\n\r\t'); +const isNotAnchorChar = (ch) => !ch || invalidAnchorChars.has(ch); /** * Splits an input string into lexical tokens, i.e. smaller strings that are * easily identifiable by `tokens.tokenType()`. @@ -149,6 +149,8 @@ class Lexer { */ *lex(source, incomplete = false) { if (source) { + if (typeof source !== 'string') + throw TypeError('source is not a string'); this.buffer = this.buffer ? this.buffer + source : source; this.lineEndPos = null; } @@ -248,11 +250,16 @@ class Lexer { } if (line[0] === '%') { let dirEnd = line.length; - const cs = line.indexOf('#'); - if (cs !== -1) { + let cs = line.indexOf('#'); + while (cs !== -1) { const ch = line[cs - 1]; - if (ch === ' ' || ch === '\t') + if (ch === ' ' || ch === '\t') { dirEnd = cs - 1; + break; + } + else { + cs = line.indexOf('#', cs + 1); + } } while (true) { const ch = line[dirEnd - 1]; @@ -283,15 +290,11 @@ class Lexer { if (!this.atEnd && !this.hasChars(4)) return this.setNext('line-start'); const s = this.peek(3); - if (s === '---' && isEmpty(this.charAt(3))) { + if ((s === '---' || s === '...') && isEmpty(this.charAt(3))) { yield* this.pushCount(3); this.indentValue = 0; this.indentNext = 0; - return 'doc'; - } - else if (s === '...' && isEmpty(this.charAt(3))) { - yield* this.pushCount(3); - return 'stream'; + return s === '---' ? 'doc' : 'stream'; } } this.indentValue = yield* this.pushSpaces(false); @@ -518,8 +521,10 @@ class Lexer { if (indent >= this.indentNext) { if (this.blockScalarIndent === -1) this.indentNext = indent; - else - this.indentNext += this.blockScalarIndent; + else { + this.indentNext = + this.blockScalarIndent + (this.indentNext === 0 ? 1 : this.indentNext); + } do { const cs = this.continueScalar(nl + 1); if (cs === -1) @@ -532,14 +537,25 @@ class Lexer { nl = this.buffer.length; } } - if (!this.blockScalarKeep) { + // Trailing insufficiently indented tabs are invalid. + // To catch that during parsing, we include them in the block scalar value. + let i = nl + 1; + ch = this.buffer[i]; + while (ch === ' ') + ch = this.buffer[++i]; + if (ch === '\t') { + while (ch === '\t' || ch === ' ' || ch === '\r' || ch === '\n') + ch = this.buffer[++i]; + nl = i - 1; + } + else if (!this.blockScalarKeep) { do { let i = nl - 1; let ch = this.buffer[i]; if (ch === '\r') ch = this.buffer[--i]; const lastChar = i; // Drop the line if last char not more indented - while (ch === ' ' || ch === '\t') + while (ch === ' ') ch = this.buffer[--i]; if (ch === '\n' && i >= this.pos && i + 1 + indent > lastChar) nl = i; @@ -559,7 +575,7 @@ class Lexer { while ((ch = this.buffer[++i])) { if (ch === ':') { const next = this.buffer[i + 1]; - if (isEmpty(next) || (inFlow && next === ',')) + if (isEmpty(next) || (inFlow && flowIndicatorChars.has(next))) break; end = i; } @@ -574,7 +590,7 @@ class Lexer { else end = i; } - if (next === '#' || (inFlow && invalidFlowScalarChars.includes(next))) + if (next === '#' || (inFlow && flowIndicatorChars.has(next))) break; if (ch === '\n') { const cs = this.continueScalar(i + 1); @@ -584,7 +600,7 @@ class Lexer { } } else { - if (inFlow && invalidFlowScalarChars.includes(ch)) + if (inFlow && flowIndicatorChars.has(ch)) break; end = i; } @@ -629,7 +645,7 @@ class Lexer { case ':': { const inFlow = this.flowLevel > 0; const ch1 = this.charAt(1); - if (isEmpty(ch1) || (inFlow && invalidFlowScalarChars.includes(ch1))) { + if (isEmpty(ch1) || (inFlow && flowIndicatorChars.has(ch1))) { if (!inFlow) this.indentNext = this.indentValue + 1; else if (this.flowKey) @@ -654,11 +670,11 @@ class Lexer { let i = this.pos + 1; let ch = this.buffer[i]; while (ch) { - if (tagChars.includes(ch)) + if (tagChars.has(ch)) ch = this.buffer[++i]; else if (ch === '%' && - hexDigits.includes(this.buffer[i + 1]) && - hexDigits.includes(this.buffer[i + 2])) { + hexDigits.has(this.buffer[i + 1]) && + hexDigits.has(this.buffer[i + 2])) { ch = this.buffer[(i += 3)]; } else diff --git a/node_modules/yaml/browser/dist/parse/parser.js b/node_modules/yaml/browser/dist/parse/parser.js index 65da03d6..d679c6dc 100644 --- a/node_modules/yaml/browser/dist/parse/parser.js +++ b/node_modules/yaml/browser/dist/parse/parser.js @@ -304,7 +304,7 @@ class Parser { } else { Object.assign(it, { key: token, sep: [] }); - this.onKeyLine = !includesToken(it.start, 'explicit-key-ind'); + this.onKeyLine = !it.explicitKey; return; } break; @@ -513,9 +513,9 @@ class Parser { return; } if (this.indent >= map.indent) { - const atNextItem = !this.onKeyLine && - this.indent === map.indent && - it.sep && + const atMapIndent = !this.onKeyLine && this.indent === map.indent; + const atNextItem = atMapIndent && + (it.sep || it.explicitKey) && this.type !== 'seq-item-ind'; // For empty nodes, assign newline-separated not indented empty tokens to following node let start = []; @@ -556,25 +556,26 @@ class Parser { } return; case 'explicit-key-ind': - if (!it.sep && !includesToken(it.start, 'explicit-key-ind')) { + if (!it.sep && !it.explicitKey) { it.start.push(this.sourceToken); + it.explicitKey = true; } else if (atNextItem || it.value) { start.push(this.sourceToken); - map.items.push({ start }); + map.items.push({ start, explicitKey: true }); } else { this.stack.push({ type: 'block-map', offset: this.offset, indent: this.indent, - items: [{ start: [this.sourceToken] }] + items: [{ start: [this.sourceToken], explicitKey: true }] }); } this.onKeyLine = true; return; case 'map-value-ind': - if (includesToken(it.start, 'explicit-key-ind')) { + if (it.explicitKey) { if (!it.sep) { if (includesToken(it.start, 'newline')) { Object.assign(it, { key: null, sep: [this.sourceToken] }); @@ -665,9 +666,7 @@ class Parser { default: { const bv = this.startBlockValue(map); if (bv) { - if (atNextItem && - bv.type !== 'block-seq' && - includesToken(it.start, 'explicit-key-ind')) { + if (atMapIndent && bv.type !== 'block-seq') { map.items.push({ start }); } this.stack.push(bv); @@ -888,7 +887,7 @@ class Parser { type: 'block-map', offset: this.offset, indent: this.indent, - items: [{ start }] + items: [{ start, explicitKey: true }] }; } case 'map-value-ind': { diff --git a/node_modules/yaml/browser/dist/schema/core/float.js b/node_modules/yaml/browser/dist/schema/core/float.js index a632cb7c..3fa9cf85 100644 --- a/node_modules/yaml/browser/dist/schema/core/float.js +++ b/node_modules/yaml/browser/dist/schema/core/float.js @@ -5,7 +5,7 @@ const floatNaN = { identify: value => typeof value === 'number', default: true, tag: 'tag:yaml.org,2002:float', - test: /^(?:[-+]?\.(?:inf|Inf|INF|nan|NaN|NAN))$/, + test: /^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/, resolve: str => str.slice(-3).toLowerCase() === 'nan' ? NaN : str[0] === '-' diff --git a/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js b/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js index 9097266b..2f06117e 100644 --- a/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js +++ b/node_modules/yaml/browser/dist/schema/yaml-1.1/float.js @@ -5,7 +5,7 @@ const floatNaN = { identify: value => typeof value === 'number', default: true, tag: 'tag:yaml.org,2002:float', - test: /^[-+]?\.(?:inf|Inf|INF|nan|NaN|NAN)$/, + test: /^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/, resolve: (str) => str.slice(-3).toLowerCase() === 'nan' ? NaN : str[0] === '-' diff --git a/node_modules/yaml/browser/dist/stringify/foldFlowLines.js b/node_modules/yaml/browser/dist/stringify/foldFlowLines.js index 2a554266..2f0bd077 100644 --- a/node_modules/yaml/browser/dist/stringify/foldFlowLines.js +++ b/node_modules/yaml/browser/dist/stringify/foldFlowLines.js @@ -9,6 +9,8 @@ const FOLD_QUOTED = 'quoted'; function foldFlowLines(text, indent, mode = 'flow', { indentAtStart, lineWidth = 80, minContentWidth = 20, onFold, onOverflow } = {}) { if (!lineWidth || lineWidth < 0) return text; + if (lineWidth < minContentWidth) + minContentWidth = 0; const endStep = Math.max(1 + minContentWidth, 1 + lineWidth - indent.length); if (text.length <= endStep) return text; diff --git a/node_modules/yaml/browser/dist/stringify/stringifyPair.js b/node_modules/yaml/browser/dist/stringify/stringifyPair.js index 0807af25..353124cc 100644 --- a/node_modules/yaml/browser/dist/stringify/stringifyPair.js +++ b/node_modules/yaml/browser/dist/stringify/stringifyPair.js @@ -10,7 +10,7 @@ function stringifyPair({ key, value }, ctx, onComment, onChompKeep) { if (keyComment) { throw new Error('With simple keys, key nodes cannot have comments'); } - if (isCollection(key)) { + if (isCollection(key) || (!isNode(key) && typeof key === 'object')) { const msg = 'With simple keys, collection cannot be used as a key value'; throw new Error(msg); } |
