toml: solidify single-line escape validation (#12644)

pull/12664/head
Larpon 2021-12-02 11:07:53 +01:00 committed by GitHub
parent adddac4807
commit 7d0a36dd08
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 9 deletions

View File

@ -437,17 +437,24 @@ fn (c Checker) check_quoted_escapes(q ast.Quoted) ? {
escape := ch_byte.ascii_str() + next_ch.ascii_str() escape := ch_byte.ascii_str() + next_ch.ascii_str()
if is_basic { if is_basic {
if q.is_multiline { if q.is_multiline {
if next_ch == byte(32) { if next_ch == ` ` {
if s.peek(1) == byte(92) {
st := s.state()
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' can not escape whitespaces before escapes in multi-line strings (`\\ \\`) at `$escape` ($st.line_nr,$st.col) in ...${c.excerpt(q.pos)}...')
}
if !contains_newlines { if !contains_newlines {
st := s.state() st := s.state()
return error(@MOD + '.' + @STRUCT + '.' + @FN + return error(@MOD + '.' + @STRUCT + '.' + @FN +
' can not escape whitespaces in multi-line strings (`\\ `) at `$escape` ($st.line_nr,$st.col) in ...${c.excerpt(q.pos)}...') ' can not escape whitespaces in multi-line strings (`\\ `) at `$escape` ($st.line_nr,$st.col) in ...${c.excerpt(q.pos)}...')
} }
// Rest of line must only be space chars from this point on
for {
ch_ := s.next()
if ch_ == scanner.end_of_text || ch_ == `\n` {
break
}
if !(ch_ == ` ` || ch_ == `\t`) {
st := s.state()
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' invalid character `${byte(ch_).ascii_str()}` after `$escape` at ($st.line_nr,$st.col) in ...${c.excerpt(q.pos)}...')
}
}
} }
if next_ch in [`\t`, `\n`, ` `] { if next_ch in [`\t`, `\n`, ` `] {
s.next() s.next()

View File

@ -14,9 +14,7 @@ const (
'valid/example-v0.4.0.toml', 'valid/example-v0.4.0.toml',
'valid/datetime-truncate.toml', // Not considered valid since RFC 3339 doesn't permit > 6 ms digits ?? 'valid/datetime-truncate.toml', // Not considered valid since RFC 3339 doesn't permit > 6 ms digits ??
] ]
invalid_exceptions = [ invalid_exceptions = []string{}
'invalid/string-bad-line-ending-escape.toml',
]
valid_value_exceptions = [ valid_value_exceptions = [
// These have correct values, and should've passed, but the format of arrays is *mixed* in the JSON ?? // These have correct values, and should've passed, but the format of arrays is *mixed* in the JSON ??