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

Escape quotation marks in text encoding #152

Merged
merged 1 commit into from
May 13, 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
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\"\'\\")`, `(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm okay with merging this optimistically, but could you just give me a bit of context about what's going on here? The change seems very simple, but I'm not familiar with this part of the code base, so I just want to do my due diligence. 🙂

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume this is just expanding the test, to cover the characters relevant to this patch.

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");
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. Can you just explain like I'm 5 what the 22275c corresponds to and why it's needed?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is just the hex encoding of the characters added above.

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