diff options
Diffstat (limited to 'resources')
-rw-r--r-- | resources/images/exif/exif.go | 15 | ||||
-rw-r--r-- | resources/images/exif/exif_test.go | 17 |
2 files changed, 23 insertions, 9 deletions
diff --git a/resources/images/exif/exif.go b/resources/images/exif/exif.go index 065c14355..5406665cf 100644 --- a/resources/images/exif/exif.go +++ b/resources/images/exif/exif.go @@ -226,17 +226,14 @@ func (e *exifWalker) Walk(f _exif.FieldName, tag *tiff.Tag) error { func nullString(in []byte) string { var rv bytes.Buffer - for _, b := range in { - if unicode.IsGraphic(rune(b)) { - rv.WriteByte(b) + for len(in) > 0 { + r, size := utf8.DecodeRune(in) + if unicode.IsGraphic(r) { + rv.WriteRune(r) } + in = in[size:] } - rvs := rv.String() - if utf8.ValidString(rvs) { - return rvs - } - - return "" + return rv.String() } var tcodec *tmc.Codec diff --git a/resources/images/exif/exif_test.go b/resources/images/exif/exif_test.go index 69540ddf5..0cb9f6704 100644 --- a/resources/images/exif/exif_test.go +++ b/resources/images/exif/exif_test.go @@ -89,6 +89,23 @@ func TestIssue8079(t *testing.T) { c.Assert(x.Tags["ImageDescription"], qt.Equals, "Città del Vaticano #nanoblock #vatican #vaticancity") } +func TestNullString(t *testing.T) { + c := qt.New(t) + + for _, test := range []struct { + in string + expect string + }{ + {"foo", "foo"}, + {"\x20", "\x20"}, + {"\xc4\x81", "\xc4\x81"}, // \u0101 + {"\u0160", "\u0160"}, // non-breaking space + } { + res := nullString([]byte(test.in)) + c.Assert(res, qt.Equals, test.expect) + } +} + func BenchmarkDecodeExif(b *testing.B) { c := qt.New(b) f, err := os.Open(filepath.FromSlash("../../testdata/sunset.jpg")) |