toml: fix handling of multiline string with CRLF (fix #24321) (#24322)

This commit is contained in:
kbkpbot 2025-04-26 12:59:18 +08:00 committed by GitHub
parent fa41436852
commit b87aed84e3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 0 deletions

View File

@ -486,6 +486,9 @@ fn (mut s Scanner) extract_multiline_string() !string {
c := u8(s.at()) c := u8(s.at())
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'c: `${c.ascii_str()}` / ${c} (quote type: ${quote}/${quote.ascii_str()})') util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'c: `${c.ascii_str()}` / ${c} (quote type: ${quote}/${quote.ascii_str()})')
if c == `\r` {
continue
}
if c == `\n` { if c == `\n` {
s.inc_line_number() s.inc_line_number()
lit += c.ascii_str() lit += c.ascii_str()

View File

@ -80,3 +80,16 @@ fn test_reset() {
s.reset() s.reset()
assert s.next() == `a` assert s.next() == `a`
} }
const multiline_string_input = input.Config{
text: '"""abc\r\ndef\n123"""'
}
fn test_multiline_string() {
mut s := scanner.new_scanner(input: multiline_string_input) or { panic(err) }
tok := s.scan()!
assert tok.kind == .quoted
assert tok.lit.contains('abc')
assert tok.lit.contains('def')
assert tok.lit.contains('123')
}