-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes a bug where JSON object keys were not escaped
- Loading branch information
Showing
4 changed files
with
73 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"id": "461d165a-25e3-4666-9f07-6407175b6bd5", | ||
"type": "bugfix", | ||
"description": "Fixes a bug where JSON object keys were not escaped.", | ||
"modules": [ | ||
"." | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package json | ||
|
||
import ( | ||
"bytes" | ||
"testing" | ||
) | ||
|
||
func TestEscapeStringBytes(t *testing.T) { | ||
cases := map[string]struct { | ||
expected string | ||
input []byte | ||
}{ | ||
"safeSet only": { | ||
expected: `"mountainPotato"`, | ||
input: []byte("mountainPotato"), | ||
}, | ||
"parenthesis": { | ||
expected: `"foo\""`, | ||
input: []byte(`foo"`), | ||
}, | ||
"double escape": { | ||
expected: `"hello\\\\world"`, | ||
input: []byte(`hello\\world`), | ||
}, | ||
"new line": { | ||
expected: `"foo\nbar"`, | ||
input: []byte("foo\nbar"), | ||
}, | ||
"carriage return": { | ||
expected: `"foo\rbar"`, | ||
input: []byte("foo\rbar"), | ||
}, | ||
"tab": { | ||
expected: `"foo\tbar"`, | ||
input: []byte("foo\tbar"), | ||
}, | ||
} | ||
for name, c := range cases { | ||
t.Run(name, func(t *testing.T) { | ||
var buffer bytes.Buffer | ||
escapeStringBytes(&buffer, c.input) | ||
expected := c.expected | ||
actual := buffer.String() | ||
if expected != actual { | ||
t.Errorf("\nexpected %v \nactual %v", expected, actual) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters