You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by ta...@apache.org on 2022/06/02 09:55:38 UTC

[tika] branch main updated: TIKA-3783 -- fix name detector to handle # before final .

This is an automated email from the ASF dual-hosted git repository.

tallison pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tika.git


The following commit(s) were added to refs/heads/main by this push:
     new cfe6c2b01 TIKA-3783 -- fix name detector to handle # before final .
     new 6d5fec611 Merge remote-tracking branch 'origin/main' into main
cfe6c2b01 is described below

commit cfe6c2b0175a98c209cec99090d01bc2e19aefec
Author: tallison <ta...@apache.org>
AuthorDate: Thu Jun 2 05:55:20 2022 -0400

    TIKA-3783 -- fix name detector to handle # before final .
---
 tika-core/src/main/java/org/apache/tika/detect/NameDetector.java     | 2 +-
 tika-core/src/test/java/org/apache/tika/detect/NameDetectorTest.java | 3 +++
 2 files changed, 4 insertions(+), 1 deletion(-)

diff --git a/tika-core/src/main/java/org/apache/tika/detect/NameDetector.java b/tika-core/src/main/java/org/apache/tika/detect/NameDetector.java
index 1b583c151..36d01e171 100644
--- a/tika-core/src/main/java/org/apache/tika/detect/NameDetector.java
+++ b/tika-core/src/main/java/org/apache/tika/detect/NameDetector.java
@@ -116,7 +116,7 @@ public class NameDetector implements Detector {
 
             // Strip any fragments from the end, but only ones after the extension
             int hash = name.lastIndexOf('#');
-            int dot = name.indexOf('.');
+            int dot = name.lastIndexOf('.');
             if (hash != -1) {
                 if (dot == -1 || hash > dot) {
                     name = name.substring(0, hash);
diff --git a/tika-core/src/test/java/org/apache/tika/detect/NameDetectorTest.java b/tika-core/src/test/java/org/apache/tika/detect/NameDetectorTest.java
index a260869ac..dc15299af 100644
--- a/tika-core/src/test/java/org/apache/tika/detect/NameDetectorTest.java
+++ b/tika-core/src/test/java/org/apache/tika/detect/NameDetectorTest.java
@@ -72,6 +72,9 @@ public class NameDetectorTest {
         assertDetect(MediaType.TEXT_PLAIN, "text#123.txt");// # before extension
         assertDetect(MediaType.TEXT_PLAIN, "text.txt#pdf");// # after extension
 
+        // TIKA-3783 # before the final .
+        assertDetect(MediaType.TEXT_PLAIN, "ABC#192.168.0.1#2.txt");
+
         // Check # as URL fragment too
         assertDetect(MediaType.TEXT_PLAIN, "http://foo/test.txt?1=2#pdf");
         assertDetect(MediaType.TEXT_PLAIN, "http://foo/test.txt#pdf");