TIKA-4752-follow-up - #2871
Merged
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR follows up on TIKA-4752 by improving how Apache Tika determines character encodings from declared metadata and container-specific signals (notably ZIP entry name UTF-8 declarations), and by aligning some parsers to use the configurable/default encoding detector chain.
Changes:
- Teach
ZipParserto honor ZIP UTF-8 declarations via the Unicode extra field and to pass the EFS flag as aCONTENT_TYPE_HINTinto charset detection. - Extend
MetadataCharsetDetectorto consultTikaCoreProperties.CONTENT_TYPE_HINT(betweenCONTENT_TYPEandCONTENT_ENCODING) and add focused tests. - Update
DBFParserandOutlookExtractorto prefer anEncodingDetectorfromParseContextwith aDefaultEncodingDetectorfallback.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tika-parsers/.../ZipEntryNameEncodingTest.java | Adds regression tests covering ZIP entry-name UTF-8 declarations (EFS flag and Unicode extra field). |
| tika-parsers/.../ZipParser.java | Updates entry-name resolution to trust Unicode extra fields and to feed EFS as a metadata hint into detection. |
| tika-parsers/.../DBFParser.java | Switches DBF charset detection to use ParseContext’s EncodingDetector with a default fallback. |
| tika-parsers/.../OutlookExtractor.java | Refactors 7-bit charset guessing to use EncodingDetector on raw body bytes with declared charset as a hint. |
| tika-core/.../MetadataCharsetDetectorTest.java | Adds tests for CONTENT_TYPE_HINT and precedence ordering across metadata keys. |
| tika-core/.../MetadataCharsetDetector.java | Implements CONTENT_TYPE_HINT handling and updates documentation accordingly. |
Comments suppressed due to low confidence (1)
tika-parsers/tika-parsers-standard/tika-parsers-standard-modules/tika-parser-miscoffice-module/src/main/java/org/apache/tika/parser/dbf/DBFParser.java:152
- In getCharset(), the try-with-resources stream
tisis created but the detector is invoked on a freshTikaInputStream.get(bytes)instead. This bypasses the managed resource and can leak/duplicate streams. Also, when detection returns an empty list, the current code setscharsetto null, which can later trigger an NPE whencharset.toString()is called in parse(); it should fall back to the existing DEFAULT_CHARSET instead.
try (TikaInputStream tis = TikaInputStream.get(bytes)) {
List<EncodingResult> results =
detector.detect(TikaInputStream.get(bytes), new Metadata(), parseContext);
charset = results.isEmpty() ? null : results.get(0).getCharset();
}
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
# Conflicts: # tika-core/src/main/java/org/apache/tika/detect/MetadataCharsetDetector.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Thanks for your contribution to Apache Tika! Your help is appreciated!
Before opening the pull request, please verify that
TIKA-XXXX)[TIKA-XXXX] Issue or pull request title)./mvnw clean testmainbranch. If there are conflicts, please try to rebase the pull request branch on top of a freshly pulledmainbranchtika-bom/pom.xml.We will be able to faster integrate your pull request if these conditions are met. If you have any questions how to fix your problem or about using Tika in general, please sign up for the Tika mailing list. Thanks!