From 1b5a25c0ef351113c169c72a61c1522cd7c3d788 Mon Sep 17 00:00:00 2001 From: Thomas Pelletier Date: Wed, 24 Nov 2021 18:11:36 -0500 Subject: [PATCH] Decoder: fail on unescaped \r not followed by \n (#681) Fixes #674 --- scanner.go | 8 ++++++++ unmarshaler_test.go | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/scanner.go b/scanner.go index 6161799..4884713 100644 --- a/scanner.go +++ b/scanner.go @@ -242,6 +242,14 @@ func scanMultilineBasicString(b []byte) ([]byte, bool, []byte, error) { } escaped = true i++ // skip the next character + case '\r': + if len(b) < i+2 { + return nil, escaped, nil, newDecodeError(b[len(b):], `need a \n after \r`) + } + if b[i+1] != '\n' { + return nil, escaped, nil, newDecodeError(b[i:i+2], `need a \n after \r`) + } + i++ // skip the \n } } diff --git a/unmarshaler_test.go b/unmarshaler_test.go index 9f906ed..b2bc7be 100644 --- a/unmarshaler_test.go +++ b/unmarshaler_test.go @@ -2590,6 +2590,14 @@ world'`, desc: `carriage return inside basic string`, data: "A = \"\r\"", }, + { + desc: `carriage return inside basic multiline string`, + data: "a=\"\"\"\r\"\"\"", + }, + { + desc: `carriage return at the trail of basic multiline string`, + data: "a=\"\"\"\r", + }, { desc: `carriage return inside literal string`, data: "A = '\r'",