Repository navigation
fix: handle encoding for text file checks - #707
Merged
Merged
Conversation
qued
approved these changes
Jun 9, 2023
qued
left a comment
Contributor
There was a problem hiding this comment.
LGTM! Errors on main when running the test code, no errors on this branch.
2sumtech
added a commit
to 2sumtech/unstructured
that referenced
this pull request
Aug 24, 2026
_TextFileDifferentiator._is_json parsed the raw byte stream with
json.load(), which auto-detects only the UTF-8/16/32 family, and caught
only json.JSONDecodeError. A plain-text file in any other character set
(e.g. cp1252/latin-1) whose first non-whitespace character is { or [ --
a log file or INI-style config -- raised UnicodeDecodeError out of
detect_filetype() and partition() instead of classifying as TXT.
Treat an undecodable payload as not-JSON after retrying with the
declared encoding, so an explicitly-declared legacy-encoded JSON file
still classifies as JSON. Regression of the encoding-aware detection
fixed in Unstructured-IO#707 (issue Unstructured-IO#705), reintroduced when detection was rewritten.
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.
Summary
Closes #705. Updates the text file checks for JSON and CSV structured in
detect_filetypeto handle documents with different encodings.Testing
This code should now run without error