Skip to content

fix(loaders): stop BoxLoader from mangling binary file content - #1044

Merged
AmitoVrito merged 1 commit into
mainfrom
fix/box-loader-binary-content-1030
Sep 15, 2026
Merged

AmitoVrito merged 1 commit into
mainfrom
fix/box-loader-binary-content-1030

Conversation

@AmitoVrito

Copy link
Copy Markdown
Collaborator

Summary

  • BoxLoader.load() unconditionally ran content.decode("utf-8", errors="replace") on every downloaded file, so PDFs/images/other binaries became mojibake instead of being flagged as binary.
  • Now attempts a strict UTF-8 decode; on UnicodeDecodeError it emits a [Binary file: <content-type or extension>] placeholder and preserves the raw bytes in metadata["raw_content"] (plus metadata["content_type"] sourced from the response headers), matching the pattern S3Loader already uses.
  • Kept the fix scoped to detect-and-placeholder (one of the two options the issue proposed) rather than also wiring in the full PDF/DOCX/etc. extractor pipeline, to keep this change small and focused.

Test plan

  • Added test_box_loader_does_not_mangle_binary_content — confirmed it fails on the pre-fix code (mojibake text) and passes after the fix.
  • Existing Box loader tests (test_box_loader_loads_file_content, test_box_loader_follows_folder_pagination) still pass unchanged.
  • ruff check, ruff format --check, mypy clean on touched files.

Closes #1030

Fixes #1030. load() unconditionally did
content.decode("utf-8", errors="replace") on every downloaded file,
turning PDFs/images/other binaries into mojibake. Non-decodable
content now gets a "[Binary file: <content-type or extension>]"
placeholder with the raw bytes kept in metadata["raw_content"],
matching S3Loader's pattern.

Co-authored-by: Dhruv Garg <[email protected]>
@AmitoVrito
AmitoVrito merged commit c0d0e8f into main Sep 15, 2026
24 checks passed
@AmitoVrito
AmitoVrito deleted the fix/box-loader-binary-content-1030 branch September 15, 2026 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BoxLoader decodes all file content as UTF-8 (binaries mangled)

1 participant