Decoder: flag invalid carriage returns in literal strings (#673)

This commit is contained in:
Cameron Moore
2021-11-23 21:41:59 -06:00
committed by GitHub
parent 64fe47161f
commit 8645d6376b
2 changed files with 9 additions and 1 deletions
+1 -1
View File
@@ -53,7 +53,7 @@ func scanLiteralString(b []byte) ([]byte, []byte, error) {
switch b[i] { switch b[i] {
case '\'': case '\'':
return b[:i+1], b[i+1:], nil return b[:i+1], b[i+1:], nil
case '\n': case '\n', '\r':
return nil, nil, newDecodeError(b[i:i+1], "literal strings cannot have new lines") return nil, nil, newDecodeError(b[i:i+1], "literal strings cannot have new lines")
} }
size := utf8ValidNext(b[i:]) size := utf8ValidNext(b[i:])
+8
View File
@@ -2544,10 +2544,18 @@ world'`,
desc: `carriage return inside basic key`, desc: `carriage return inside basic key`,
data: "\"\r\"=42", data: "\"\r\"=42",
}, },
{
desc: `carriage return inside literal key`,
data: "'\r'=42",
},
{ {
desc: `carriage return inside basic string`, desc: `carriage return inside basic string`,
data: "A = \"\r\"", data: "A = \"\r\"",
}, },
{
desc: `carriage return inside literal string`,
data: "A = '\r'",
},
{ {
desc: `carriage return in comment`, desc: `carriage return in comment`,
data: "# this is a test\ra=1", data: "# this is a test\ra=1",