Skip to content

Commit

Permalink
fix(lexer): Account for CRLF during quoted-scalar unindent (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed Sep 6, 2021
1 parent 222e792 commit eee3cec
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/parse/lexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ export class Lexer {
}
if (nl !== -1) {
// this is an error caused by an unexpected unindent
end = nl - 1
end = nl - (qb[nl - 1] === '\r' ? 2 : 1)
}
}
if (end === -1) {
Expand Down
12 changes: 12 additions & 0 deletions tests/lexer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { Lexer } from 'yaml'

test('unexpected unindent in quoted string with CRLF', () => {
const src = '- "\r\nx"'
let n = 0
const res: string[] = []
for (const lex of new Lexer().lex(src)) {
res.push(lex)
if (++n === 10) break
}
expect(res).toEqual(['\u0002', '-', ' ', '"', '\r\n', '\u001f', 'x"'])
})

0 comments on commit eee3cec

Please sign in to comment.