kisielk / og-rek

ogórek is a Go library for encoding and decoding pickles.
MIT License
60 stars 16 forks source link

encoder: Fix protocol 0 UNICODE emission for invalid UTF-8 #67

Closed navytux closed 3 months ago

navytux commented 3 months ago

Please see individual patches for details.

navytux commented 3 months ago

(adjusted the first patch to also come with tests)

interdiff:

--- a/ogorek_test.go
+++ b/ogorek_test.go
@@ -964,6 +964,24 @@ func TestUnquoteCharEOF(t *testing.T) {
        }
 }

+func TestStringsFmt(t *testing.T) {
+       tvhash := []struct{
+               in      interface{}
+               vhashok string
+       }{
+               {"мир",          `"мир"`},
+               {Bytes("мир"),   `ogórek.Bytes("мир")`},
+               {unicode("мир"), `ogórek.unicode("мир")`},
+       }
+
+       for _, tt := range tvhash {
+               vhash := fmt.Sprintf("%#v", tt.in)
+               if vhash != tt.vhashok {
+                       t.Errorf("%T %q: %%#v:\nhave: %s\nwant: %s", tt.in, tt.in, vhash, tt.vhashok)
+               }
+       }
+}
+
 // like io.LimitedReader but for writes
 // XXX it would be good to have it in stdlib
 type LimitedWriter struct {
navytux commented 3 months ago

Kamil, thanks for the approval.

navytux commented 3 months ago

I appled the patches to master myself as 1fea98e4f7aeffc5c3cb0d4cf87dd61877715b89 and 09fec8bdc113401306abc6280a8d0f3a99d9c48b. Hope it is ok.