Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decoder: fail on unescaped \r not followed by \n #681

Merged
merged 1 commit into from
Nov 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
8 changes: 8 additions & 0 deletions unmarshaler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
Expand Down