diff options
| author | littleblack111 <littleblack11111@gmail.com> | 2024-08-30 17:21:18 +0800 |
|---|---|---|
| committer | littleblack111 <littleblack11111@gmail.com> | 2024-08-30 17:21:18 +0800 |
| commit | efbc2ffe6a1ee5ec38a4396305561d6515d0943e (patch) | |
| tree | 2b4c94f18f2c792dfda813050755d5c0273fae22 /node_modules/yaml/dist/parse/lexer.js | |
| parent | 43acceb75957c880a5ba5a31aae221394a36d5f6 (diff) | |
node fixes, updates
Diffstat (limited to 'node_modules/yaml/dist/parse/lexer.js')
| -rw-r--r-- | node_modules/yaml/dist/parse/lexer.js | 66 |
1 files changed, 41 insertions, 25 deletions
diff --git a/node_modules/yaml/dist/parse/lexer.js b/node_modules/yaml/dist/parse/lexer.js index f408ce49..9ac766e9 100644 --- a/node_modules/yaml/dist/parse/lexer.js +++ b/node_modules/yaml/dist/parse/lexer.js @@ -81,11 +81,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()`. @@ -151,6 +151,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; } @@ -250,11 +252,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]; @@ -285,15 +292,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); @@ -520,8 +523,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) @@ -534,14 +539,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; @@ -561,7 +577,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; } @@ -576,7 +592,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); @@ -586,7 +602,7 @@ class Lexer { } } else { - if (inFlow && invalidFlowScalarChars.includes(ch)) + if (inFlow && flowIndicatorChars.has(ch)) break; end = i; } @@ -631,7 +647,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) @@ -656,11 +672,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 |
