Skip to content

Commit 112110b

Browse files
committed
Drop warning for UserComment type assertion
It's too common to warn about.
1 parent 741c616 commit 112110b

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

‎helpers.go‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@ func (vc) convertStringToInt(ctx valueConverterContext, v any) any {
294294

295295
func (c vc) convertUserComment(ctx valueConverterContext, v any) any {
296296
// UserComment tag is identified based on an ID code in a fixed 8-byte area at the start of the tag data area.
297-
b, ok := typeAssert[[]byte](ctx, v)
297+
b, ok := typeAssertNoWarn[[]byte](ctx, v)
298298
if !ok {
299299
// Handle plain string user comment (which is against spec; but commonly done)
300300
// Exiftool prints a warning but returns the string as-is.
@@ -499,3 +499,8 @@ func typeAssert[T any](ctx valueConverterContext, v any) (T, bool) {
499499
}
500500
return vv, true
501501
}
502+
503+
func typeAssertNoWarn[T any](ctx valueConverterContext, v any) (T, bool) {
504+
vv, ok := v.(T)
505+
return vv, ok
506+
}

‎imagemeta_test.go‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -188,9 +188,7 @@ func TestDecodeUserCommentWithInvalidEncoding(t *testing.T) {
188188
return nil
189189
}
190190

191-
var warning error
192191
warnf := func(format string, args ...any) {
193-
warning = fmt.Errorf(format, args...)
194192
}
195193

196194
err = imagemeta.Decode(imagemeta.Options{R: img, ImageFormat: imagemeta.JPEG, HandleTag: handleTag, Sources: imagemeta.EXIF, Warnf: warnf})
@@ -199,9 +197,6 @@ func TestDecodeUserCommentWithInvalidEncoding(t *testing.T) {
199197
// Expect user comment to be decoded
200198
c.Assert(userComment, qt.IsNotNil)
201199
c.Assert(userComment, eq, "UserComment")
202-
203-
// But with a warning about incorrect type
204-
c.Assert(warning, qt.ErrorMatches, "UserComment: expected \\[\\]uint8, got string")
205200
}
206201

207202
func TestDecodeCustomXMPHandler(t *testing.T) {

0 commit comments

Comments
 (0)