cue/scanner: reject closing quotes of multiline strings not after a newline
The spec grammar requires that multiline strings end with a newline
right before the closing quote:
multiline_string_lit = `"""` newline
{ unicode_value | interpolation | newline }
newline `"""` .
multiline_bytes_lit = "'''" newline
{ unicode_value | interpolation | byte_value | newline }
newline "'''" .
The scanner was not enforcing this, accepting inputs like `"""\n0"""`
where the closing `"""` appears on the same line as content.
This caused a disagreement between cue/parser and cue/literal,
as literal.Unquote correctly rejects such strings.
Fix scanString to track whether we are at the start of a line
(after a newline and optional whitespace indentation), and only
attempt to match the closing quotes of a multiline string when
at the start of a line.
Found by the fuzzer changes in the following commit.
Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Ib1bba21c3083e8c30b1614ef7f20dc6e474a311a
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1234634
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Matthew Sackman <matthew@cue.works>