scanner: handle carriage return in comments (#656)

Fixes #653
This commit is contained in:
Thomas Pelletier
2021-11-04 21:40:16 -04:00
committed by GitHub
parent 6617e7e73d
commit 74d21b367f
2 changed files with 26 additions and 0 deletions
+6
View File
@@ -149,6 +149,12 @@ func scanComment(b []byte) ([]byte, []byte, error) {
if b[i] == '\n' {
return b[:i], b[i:], nil
}
if b[i] == '\r' {
if i+1 < len(b) && b[i+1] == '\n' {
return b[:i+1], b[i+1:], nil
}
return nil, nil, newDecodeError(b[i:i+1], "invalid character in comment")
}
size := utf8ValidNext(b[i:])
if size == 0 {
return nil, nil, newDecodeError(b[i:i+1], "invalid character in comment")
+20
View File
@@ -1557,6 +1557,18 @@ B = "data"`,
}
},
},
{
desc: "comment with CRLF",
input: "# foo\r\na=2",
gen: func() test {
doc := map[string]interface{}{}
return test{
target: &doc,
expected: &map[string]interface{}{"a": int64(2)},
}
},
},
}
for _, e := range examples {
@@ -2219,6 +2231,14 @@ world'`,
desc: `carriage return inside basic string`,
data: "A = \"\r\"",
},
{
desc: `carriage return in comment`,
data: "# this is a test\ra=1",
},
{
desc: `backspace in comment`,
data: "# this is a test\ba=1",
},
}
for _, e := range examples {