Copilot commented on code in PR #3116:
URL: https://github.com/apache/tika/pull/3116#discussion_r3915874240
##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-image-module/src/main/java/org/apache/tika/parser/image/HeifParser.java:
##########
@@ -41,7 +41,8 @@ public class HeifParser extends AbstractImageParser {
private static final Set<MediaType> SUPPORTED_TYPES = new HashSet<>(
Arrays.asList(MediaType.image("heif"),
MediaType.image("heif-sequence"),
- MediaType.image("heic"),
MediaType.image("heic-sequence")));
+ MediaType.image("heic"), MediaType.image("heic-sequence"),
+ MediaType.image("avif")));
Review Comment:
`SUPPORTED_TYPES` is a mutable `HashSet` stored in a `static final` field.
Since this is effectively constant parser configuration, making it unmodifiable
avoids accidental mutation (including from tests via reflection) and keeps the
supported-type contract stable. Consider wrapping in
`Collections.unmodifiableSet(...)` (or using an immutable-set construction used
elsewhere in the codebase).
##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-image-module/src/main/java/org/apache/tika/parser/image/HeifParser.java:
##########
@@ -41,7 +41,8 @@ public class HeifParser extends AbstractImageParser {
private static final Set<MediaType> SUPPORTED_TYPES = new HashSet<>(
Arrays.asList(MediaType.image("heif"),
MediaType.image("heif-sequence"),
- MediaType.image("heic"),
MediaType.image("heic-sequence")));
+ MediaType.image("heic"), MediaType.image("heic-sequence"),
+ MediaType.image("avif")));
Review Comment:
If the project defines/uses `image/avif-sequence` (parallel to
`heif-sequence` / `heic-sequence`), it would be better to include it here as
well so the parser contract matches the AVIF media-type family. This won’t fix
current animated-AVIF detection by itself, but it prevents a future gap where
detection is corrected yet no parser claims the resulting media type.
##########
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-image-module/src/test/java/org/apache/tika/parser/image/HeifParserTest.java:
##########
@@ -84,4 +85,25 @@ public void testAppleLivePhotoMakerNote() throws Exception {
}
}
+ /*
+ testAVIF_XMP.avif is a 32x32 gradient encoded with libavif through
+ ImageMagick, with an XMP packet attached: AVIF is the same ISO-BMFF
+ container, so the same parser reads it (TIKA-4870).
+ */
+ @Test
+ public void testAvif() throws Exception {
+ Metadata metadata = new Metadata();
+ try (TikaInputStream tis =
getResourceAsStream("/test-documents/testAVIF_XMP.avif")) {
+ parser.parse(tis, new DefaultHandler(), metadata, new
ParseContext());
+
+ assertEquals("image/avif", metadata.get(HttpHeaders.CONTENT_TYPE));
+ assertEquals("avif",
metadata.get(ImageMetadataExtractor.UNKNOWN_IMG_NS + "Major Brand"));
+ assertEquals("32 pixels",
metadata.get(ImageMetadataExtractor.UNKNOWN_IMG_NS + "Width"));
+ assertEquals("32 pixels",
metadata.get(ImageMetadataExtractor.UNKNOWN_IMG_NS + "Height"));
+ //the XMP item is found through meta/iinf/iloc, as it is for HEIC
+ assertEquals("AVIF XMP Title",
metadata.get(TikaCoreProperties.TITLE));
+ assertEquals("Jane Photographer",
metadata.get(TikaCoreProperties.CREATOR));
Review Comment:
`TikaCoreProperties.CREATOR` can be multi-valued. Using `metadata.get(...)`
only asserts the first value; if the parser starts returning multiple creators
(or merges values), this test could miss regressions. Consider asserting
against `metadata.getValues(TikaCoreProperties.CREATOR)` (e.g., exact array
match or contains-check) to make the expectation explicit.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]