diff --git a/scanner.go b/scanner.go index 25b5b58..1c5b158 100644 --- a/scanner.go +++ b/scanner.go @@ -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") diff --git a/unmarshaler_test.go b/unmarshaler_test.go index 8aa1606..8b9c8d4 100644 --- a/unmarshaler_test.go +++ b/unmarshaler_test.go @@ -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 {