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 2021/04/30 21:00:32 UTC

[tika] branch branch_1x updated: TIKA-3374 -- allow users to turn off charset detection of entry names in ZipArchives

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

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


The following commit(s) were added to refs/heads/branch_1x by this push:
     new 7cae30e  TIKA-3374 -- allow users to turn off charset detection of entry names in ZipArchives
7cae30e is described below

commit 7cae30e069e1779a909042f4bf63b023b5e248fe
Author: tballison <ta...@apache.org>
AuthorDate: Fri Apr 30 17:00:19 2021 -0400

    TIKA-3374 -- allow users to turn off charset detection of entry names in ZipArchives
---
 .../java/org/apache/tika/parser/pkg/PackageParser.java  | 17 ++++++++++++++++-
 1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/tika-parsers/src/main/java/org/apache/tika/parser/pkg/PackageParser.java b/tika-parsers/src/main/java/org/apache/tika/parser/pkg/PackageParser.java
index 0778d01..bc3cd17 100644
--- a/tika-parsers/src/main/java/org/apache/tika/parser/pkg/PackageParser.java
+++ b/tika-parsers/src/main/java/org/apache/tika/parser/pkg/PackageParser.java
@@ -47,6 +47,7 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
 import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
 import org.apache.commons.io.input.CloseShieldInputStream;
 
+import org.apache.tika.config.Field;
 import org.apache.tika.detect.EncodingDetector;
 import org.apache.tika.exception.EncryptedDocumentException;
 import org.apache.tika.exception.TikaException;
@@ -233,6 +234,9 @@ public class PackageParser extends AbstractEncodingDetectorParser {
         return type.equals(ZIP) || type.equals(JAR);
     }
 
+    private boolean detectCharsetsInEntryNames = true;
+
+
     public PackageParser() {
         super();
     }
@@ -423,7 +427,7 @@ public class PackageParser extends AbstractEncodingDetectorParser {
             throws SAXException, IOException, TikaException {
         String name = entry.getName();
         //Try to detect charset of archive entry in case of non-unicode filename is used
-        if (entry instanceof ZipArchiveEntry) {
+        if (detectCharsetsInEntryNames && entry instanceof ZipArchiveEntry) {
             Charset candidate =
                     getEncodingDetector().detect(new ByteArrayInputStream(((ZipArchiveEntry) entry).getRawName()),
                             parentMetadata);
@@ -532,4 +536,15 @@ public class PackageParser extends AbstractEncodingDetectorParser {
             file.close();
         }
     }
+
+    /**
+     * Whether or not to run the default charset detector against entry
+     * names in ZipFiles. The default is <code>true</code>.
+     *
+     * @param detectCharsetsInEntryNames
+     */
+    @Field
+    public void setDetectCharsetsInEntryNames(boolean detectCharsetsInEntryNames) {
+        this.detectCharsetsInEntryNames = detectCharsetsInEntryNames;
+    }
 }