From 9fd01b2800d3a08dde2c0047635c50dc020885ab Mon Sep 17 00:00:00 2001 From: Jake Riesterer Date: Fri, 7 Feb 2020 18:39:52 -0600 Subject: [PATCH] Escape quotation marks in text encoding The switch statement [here](https://github.com/capnproto/go-capnproto2/blob/503c1bb7bbe95734920325b8999cc89b8b79fcfa/internal/strquote/strquote.go#L29-L34) is attempting to escape quotation marks, but since `needsEscape` didn't return `true` for quotation marks, they never made it into the switch statement, and therefore weren't getting escaped. --- CONTRIBUTORS | 1 + encoding/text/marshal_test.go | 4 ++-- encoding/text/testdata/txt.capnp | 2 +- encoding/text/testdata/txt.capnp.out | Bin 10696 -> 11808 bytes internal/strquote/strquote.go | 2 +- 5 files changed, 5 insertions(+), 4 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 9a1aa311..7c27b36f 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -22,6 +22,7 @@ Dominik Roos Eran Duchan Evan Shaw Ian Denhardt +Jake Riesterer James McKaskill Jason E. Aten Johan Hernandez diff --git a/encoding/text/marshal_test.go b/encoding/text/marshal_test.go index 992a520d..f2198e67 100644 --- a/encoding/text/marshal_test.go +++ b/encoding/text/marshal_test.go @@ -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 = [ diff --git a/encoding/text/testdata/txt.capnp b/encoding/text/testdata/txt.capnp index eae50187..6c0aeb73 100644 --- a/encoding/text/testdata/txt.capnp +++ b/encoding/text/testdata/txt.capnp @@ -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]); diff --git a/encoding/text/testdata/txt.capnp.out b/encoding/text/testdata/txt.capnp.out index fd5d3cdf9771a1462ed132b0b73318f428887bf0..0a25a184f4539d7612d127a12ed2c9f657ce30b0 100644 GIT binary patch literal 11808 zcmd^FYm8OZ72Y#2JVjvuf#D^TW`tCWFapIkwS#F9q?M*MmY9Y+%mqgWW*jb$X)y&- z(t@Bc0gD71CC~`bghFF2kru|9wBsK_?ITnXM%z+FQ7e}B^!v_PYu|nM+&yQg-u~&H zoV(6iYkzC4v(G+jKV}yhl&;1!7x6|*SJMx-XSy46w2v`Vp-Mzsgf|9Cl>2a%m~Lj( zpT|#}_oWl-dPLIj&+A=`X@L49=z<)d`7yWcYKP z+-1->vRHMVyekmI&*mOFIOoN48)Cc0+AYpO8}lnX?*U*AgSuu8f?p=KTyoDV>D_-i zarzguTZ~KF#jV5pA*iqibQGv-cR2XTer51q-!|u`Co7&mM7w+!A-lA<4*Id4-7(<1 zpasW+7DsOql~6A3-8iWAu@#R)+@akspu#@X`3k5T?-#+-?sQPs?vI}O?#P>8x%CZ* zJG46+71$2n0d?(u3q0-41$FI~+}OAAj-M>}Im8{>tw9CaeF)UGTMM3cmxH=??;ZT{ z9iu+G=23_{w9B?-w@rI?>5KBCLP4T3YV)#9ul?roswBH*024n|sKCt(;Tt^pfyvXq z_RQA)%}I9m3GS$eZxy~5Iw@{#S+RHL{`ZH_s>8 zJtnvd9=;dy1>>9`R0Dqg=mV!8A6j`S$!>$-nmqgt;afcUt|jG1*3Rs*Kgn(xK1Rkh zRj9@_L-+HIBWVcyxtseeE;mh!GyZv`@ z?;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TGZ-(rE9GGT`S(qy0CiC;t z=9lUHx$Kep$K(ClV2!k3l!=$ol9A=bhP!75@}>^;9Hu8(3vFZaR%Tglp^y2)-1?Tm zy7wl_&z`6B9j2Nx=C@#F{zh*7#4>x=7ytb^OX)$Tj&f0B%)iO4_naAu{C%M>M(I^> z*w}e3vx&}kFu$K$-*(A!>ZkbhM@I63C>4$|^*R@I2mN5pBEtu+^Pkpza{Hi>h!DO} zPm47&n<&r{w++g>g}s?|*hK~88858P#5pTPju+(Rraq(aT9lpcfyi?Ovv?Zh%0p%w So(TLip?q$W4T7H-Nc|5tiM;m! diff --git a/internal/strquote/strquote.go b/internal/strquote/strquote.go index f6af09b9..b8d872d9 100644 --- a/internal/strquote/strquote.go +++ b/internal/strquote/strquote.go @@ -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 {