You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ni...@apache.org on 2014/05/21 17:01:56 UTC
svn commit: r1596593 - in /tika/trunk/tika-core/src/test:
java/org/apache/tika/mime/MimeDetectionTest.java
resources/org/apache/tika/mime/custom-mimetypes.xml
Author: nick
Date: Wed May 21 15:01:55 2014
New Revision: 1596593
URL: http://svn.apache.org/r1596593
Log:
Add a disabled unit test for TIKA-1292, which when working will ensure that if we have two matching magics at the same priority, the name is used to specialise if possible, first defined if not
Modified:
tika/trunk/tika-core/src/test/java/org/apache/tika/mime/MimeDetectionTest.java
tika/trunk/tika-core/src/test/resources/org/apache/tika/mime/custom-mimetypes.xml
Modified: tika/trunk/tika-core/src/test/java/org/apache/tika/mime/MimeDetectionTest.java
URL: http://svn.apache.org/viewvc/tika/trunk/tika-core/src/test/java/org/apache/tika/mime/MimeDetectionTest.java?rev=1596593&r1=1596592&r2=1596593&view=diff
==============================================================================
--- tika/trunk/tika-core/src/test/java/org/apache/tika/mime/MimeDetectionTest.java (original)
+++ tika/trunk/tika-core/src/test/java/org/apache/tika/mime/MimeDetectionTest.java Wed May 21 15:01:55 2014
@@ -211,4 +211,31 @@ public class MimeDetectionTest {
}
}
+ /**
+ * Tests that when two magic matches both apply, and both
+ * have the same priority, we use the name to pick the
+ * right one based on the glob, or the first one we
+ * come across if not. See TIKA-1292 for more details.
+ */
+// @Test
+ public void DISABLEDtestMimeMagicClashSamePriority() throws IOException {
+ byte[] helloWorld = "Hello, World!".getBytes("UTF-8");
+ MediaType helloType = MediaType.parse("hello/world-file");
+ MediaType helloXType = MediaType.parse("hello/x-world-hello");
+ Metadata metadata;
+
+ // With a filename, picks the right one
+ metadata = new Metadata();
+ metadata.set(Metadata.RESOURCE_NAME_KEY, "test.hello.world");
+ assertEquals(helloType, mimeTypes.detect(new ByteArrayInputStream(helloWorld), metadata));
+
+ metadata = new Metadata();
+ metadata.set(Metadata.RESOURCE_NAME_KEY, "test.x-hello-world");
+ assertEquals(helloXType, mimeTypes.detect(new ByteArrayInputStream(helloWorld), metadata));
+
+ // Without, goes for the first defined
+ metadata = new Metadata();
+ metadata.set(Metadata.RESOURCE_NAME_KEY, "testingTESTINGtesting");
+ assertEquals(helloType, mimeTypes.detect(new ByteArrayInputStream(helloWorld), metadata));
+ }
}
Modified: tika/trunk/tika-core/src/test/resources/org/apache/tika/mime/custom-mimetypes.xml
URL: http://svn.apache.org/viewvc/tika/trunk/tika-core/src/test/resources/org/apache/tika/mime/custom-mimetypes.xml?rev=1596593&r1=1596592&r2=1596593&view=diff
==============================================================================
--- tika/trunk/tika-core/src/test/resources/org/apache/tika/mime/custom-mimetypes.xml (original)
+++ tika/trunk/tika-core/src/test/resources/org/apache/tika/mime/custom-mimetypes.xml Wed May 21 15:01:55 2014
@@ -33,4 +33,13 @@
</magic>
<sub-class-of type="hello/world" />
</mime-type>
+
+ <!-- This has the same match and priority, but different glob -->
+ <!-- We can use the filename to identify the difference, see TIKA-1292 -->
+ <mime-type type="hello/x-world-hello">
+ <glob pattern="*.x-hello-world" />
+ <magic priority="50">
+ <match value="Hello, World!" type="string" offset="0:13" />
+ </magic>
+ </mime-type>
</mime-info>