Skip to content

Commit ef361a6

Browse files
committed
fix(JF-1083): fix PNG matching
1 parent bac7e15 commit ef361a6

6 files changed

Lines changed: 33 additions & 19 deletions

File tree

src/main/resources/magic.xml

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -387,20 +387,10 @@
387387
<type>
388388
<mime-type>image/png</mime-type>
389389
<extension>png</extension>
390-
<description>PNG image data,</description>
391-
<match-string offset="0">\211NG</match-string>
392-
393-
<type>
394-
<mime-type>image/png</mime-type>
395-
<extension>png</extension>
396-
<description>CORRUPTED,</description>
397-
<match-long order="be" offset="4">0xd0a1a0a</match-long>
398-
</type>
399-
<type>
400-
<mime-type>image/png</mime-type>
401-
<extension>png</extension>
402-
<description></description>
403-
<match-long order="be" offset="4">0xd0a1a0a</match-long>
390+
<description>PNG image data</description>
391+
<description lang="de">PNG Bilddatei</description>
392+
<match-string offset="0">\211PNG</match-string>
393+
<match-string offset="12">IHDR</match-string>
404394

405395
<type>
406396
<mime-type>image/png</mime-type>
@@ -462,10 +452,8 @@
462452
<description>interlaced</description>
463453
<match-byte order="be" offset="28">0x1</match-byte>
464454
</type>
465-
466-
</type>
467-
468455
</type>
456+
469457
<type>
470458
<mime-type>image/png</mime-type>
471459
<extension>png</extension>

src/test/java/TestVariousTypes.java

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,33 @@ void testEmptyStream() throws Exception {
6464
assertEquals("Binary data, ASCII Text Document", results.get(DescriptionAction.KEY));
6565
}
6666

67-
public static Stream<Arguments> dataProvider() {
67+
public static Stream<Arguments> dataProviderVarious() {
68+
return Stream.of(
69+
arguments("/various_types/test.png", "image/png", "Binary data, PNG image data, colormap,", "png"),
70+
arguments("/various_types/File-PNG_8pbc_GRAY.png", "image/png", "Binary data, PNG image data, grayscale,", "png"),
71+
arguments("/various_types/File-PNG_8bpc_RGBA.png", "image/png", "Binary data, PNG image data, \\b/color RGBA,", "png"),
72+
arguments("/various_types/File-PNG_16bpc_RGBA.png", "image/png", "Binary data, PNG image data, \\b/color RGBA,", "png")
73+
);
74+
}
75+
76+
@ParameterizedTest
77+
@MethodSource("dataProviderVarious")
78+
void testVariousTypesExplicitly(String resource, String expectedMimeType, String expectedDescription, String expectedExtension) throws Exception {
79+
final URL url = getClass().getResource(resource);
80+
assertNotNull(url);
81+
final File file = new File(url.toURI());
82+
final Map<String, Object> results = analyzer.analyze(file);
83+
printResult(results);
84+
assertNotNull(results, file + " could not be analyzed");
85+
assertNotNull(results.get(MimeTypeAction.KEY), "mimeType missing");
86+
assertEquals(expectedMimeType, results.get(MimeTypeAction.KEY), "wrong mimeType");
87+
assertNotNull(results.get(DescriptionAction.KEY), "description missing");
88+
assertEquals(expectedDescription, results.get(DescriptionAction.KEY), "wrong description");
89+
assertNotNull(results.get(ExtensionAction.KEY), "could not be analyzed");
90+
assertEquals(expectedExtension, results.get(ExtensionAction.KEY), "wrong extension");
91+
}
92+
93+
public static Stream<Arguments> dataProviderXRechnung() {
6894
return Stream.of(
6995
arguments("/various_types/BASIC_Einfach.pdf", "application/pdf"),
7096
arguments("/various_types/EN16931_Einfach.pdf", "application/pdf"),
@@ -75,7 +101,7 @@ public static Stream<Arguments> dataProvider() {
75101
}
76102

77103
@ParameterizedTest
78-
@MethodSource("dataProvider")
104+
@MethodSource("dataProviderXRechnung")
79105
void testXRechnung(String resource, String expectedMimeType) throws Exception {
80106
final URL url = getClass().getResource(resource);
81107
assertNotNull(url);
81.1 KB
Loading
65.7 KB
Loading
27.7 KB
Loading
3.43 KB
Loading

0 commit comments

Comments
 (0)