Skip to content

Commit

Permalink
Merge pull request #152 from jRiest/fix-quote-encoding
Browse files Browse the repository at this point in the history
Escape quotation marks in text encoding
  • Loading branch information
zenhack authored May 13, 2021
2 parents a475cf2 + 9fd01b2 commit 186651b
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Dominik Roos <[email protected]>
Eran Duchan <[email protected]>
Evan Shaw <[email protected]>
Ian Denhardt <[email protected]>
Jake Riesterer <[email protected]>
James McKaskill <[email protected]>
Jason E. Aten <[email protected]>
Johan Hernandez <[email protected]>
Expand Down
4 changes: 2 additions & 2 deletions encoding/text/marshal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ func TestEncode(t *testing.T) {
{0x81fdbfdc91779421, `(map = [])`, `(
map = []
)`},
{0x8e85252144f61858, `(data = "Hi\xde\xad\xbe\xef\xca\xfe")`, `(
data = "Hi\xde\xad\xbe\xef\xca\xfe"
{0x8e85252144f61858, `(data = "Hi\xde\xad\xbe\xef\xca\xfe\"\'\\")`, `(
data = "Hi\xde\xad\xbe\xef\xca\xfe\"\'\\"
)`},
{0xc21398a8474837ba, `(voidList = [void, void])`, `(
voidList = [
Expand Down
2 changes: 1 addition & 1 deletion encoding/text/testdata/txt.capnp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ const mapVal @0xb167974479102805 :Value = (map = [
(key = "foo", value = (void = void)),
(key = "bar", value = (void = void)),
]);
const data @0x8e85252144f61858 :Value = (data = 0x"4869 dead beef cafe");
const data @0x8e85252144f61858 :Value = (data = 0x"4869 dead beef cafe 22275c");
const emptyMap @0x81fdbfdc91779421 :Value = (map = []);
const voidList @0xc21398a8474837ba :Value = (voidList = [void, void]);
const boolList @0xde82c2eeb3a4b07c :Value = (boolList = [true, false, true, false]);
Expand Down
Binary file modified encoding/text/testdata/txt.capnp.out
Binary file not shown.
2 changes: 1 addition & 1 deletion internal/strquote/strquote.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func Append(buf []byte, s []byte) []byte {
}

func needsEscape(b byte) bool {
return b < 0x20 || b >= 0x7f
return b < 0x20 || b >= 0x7f || b == '\'' || b == '"' || b == '\\'
}

func hexDigit(b byte) byte {
Expand Down

0 comments on commit 186651b

Please sign in to comment.