From 8645d6376b55757a431331e9baec12db95e87727 Mon Sep 17 00:00:00 2001 From: Cameron Moore Date: Tue, 23 Nov 2021 21:41:59 -0600 Subject: [PATCH] Decoder: flag invalid carriage returns in literal strings (#673) --- scanner.go | 2 +- unmarshaler_test.go | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/scanner.go b/scanner.go index 1c5b158..6161799 100644 --- a/scanner.go +++ b/scanner.go @@ -53,7 +53,7 @@ func scanLiteralString(b []byte) ([]byte, []byte, error) { switch b[i] { case '\'': 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") } size := utf8ValidNext(b[i:]) diff --git a/unmarshaler_test.go b/unmarshaler_test.go index d296675..0c30c4f 100644 --- a/unmarshaler_test.go +++ b/unmarshaler_test.go @@ -2544,10 +2544,18 @@ world'`, desc: `carriage return inside basic key`, data: "\"\r\"=42", }, + { + desc: `carriage return inside literal key`, + data: "'\r'=42", + }, { desc: `carriage return inside basic string`, data: "A = \"\r\"", }, + { + desc: `carriage return inside literal string`, + data: "A = '\r'", + }, { desc: `carriage return in comment`, data: "# this is a test\ra=1",