Skip to content

Commit

Permalink
Fix sanitizer bug where multiple escaped codes in a row cause invalid…
Browse files Browse the repository at this point in the history
… JSON generation (#145)
  • Loading branch information
samcoe authored Nov 20, 2023
1 parent debe718 commit d32c104
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
1 change: 1 addition & 0 deletions pkg/asciisanitizer/sanitizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ func (t *Sanitizer) Transform(dst, src []byte, atEOF bool) (nDst, nSrc int, err
// Add an escape character when necessary to prevent creating
// invalid JSON with our replacements.
repl = append([]byte{'\\'}, repl...)
t.addEscape = false
}
err = transfer(repl, src[:6])
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions pkg/asciisanitizer/sanitizer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ func TestSanitizerTransform(t *testing.T) {
{
name: "JSON sanitization maintains valid JSON",
json: true,
input: `\u001B \\u001B \\\u001B \\\\u001B`,
want: `^[ \\^[ \\^[ \\\\^[`,
input: `\u001B \\u001B \\\u001B \\\\u001B \\u001B\\u001B`,
want: `^[ \\^[ \\^[ \\\\^[ \\^[\\^[`,
},
{
name: "JSON C0 control character",
Expand Down

0 comments on commit d32c104

Please sign in to comment.