fix: respect ByteStream encoding in HTMLToDocument and MarkdownToDocument#11792
Open
greymoth-jp wants to merge 1 commit into
Open
fix: respect ByteStream encoding in HTMLToDocument and MarkdownToDocument#11792greymoth-jp wants to merge 1 commit into
greymoth-jp wants to merge 1 commit into
Conversation
…ment
Both converters hardcoded `.decode("utf-8")`, silently corrupting or
raising UnicodeDecodeError for non-UTF-8 sources that supply an encoding
via ByteStream.meta["encoding"]. This mirrors the existing pattern in
TextFileToDocument:
- Add `encoding` param to `__init__` (default "utf-8") in both converters
- Use `bytestream.meta.get("encoding", self.encoding)` at decode time
- Include `encoding` in HTMLToDocument.to_dict() / from_dict() round-trip
- Add unit tests for latin-1 ByteStreams via meta["encoding"] and via __init__
|
@greymoth-jp is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
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
HTMLToDocumentandMarkdownToDocumentboth hardcode.decode("utf-8"), which raisesUnicodeDecodeError(or silently corrupts output) for any non-UTF-8 ByteStream whose encoding is passed viaByteStream.meta["encoding"].TextFileToDocumentalready handles this correctly via anencodingconstructor param and abytestream.meta.get("encoding", self.encoding)fallback.This PR brings both converters into line with
TextFileToDocument:encoding: str = "utf-8"parameter toHTMLToDocument.__init__andMarkdownToDocument.__init__.decode("utf-8")calls tobytestream.meta.get("encoding", self.encoding)in therun()method of each converterencodinginHTMLToDocument.to_dict()so the param survives serialization round-trips (.from_dict()already routes throughdefault_from_dictwhich handles it automatically)test_bytestream_encoding_from_metaandtest_bytestream_encoding_from_init) for both converters using a latin-1 ByteStreamReproduction (before fix):
This PR was fully generated with an AI assistant. I have reviewed the changes and run the relevant tests (29 passed, 0 failed).
Test plan
pytest test/components/converters/test_html_to_document.py test/components/converters/test_markdown_to_document.py -k "not integration"— 29 passedtest_bytestream_encoding_from_metaandtest_bytestream_encoding_from_initadded for bothHTMLToDocumentandMarkdownToDocumenttest_serdeupdated to assertencodinground-trips throughto_dict/from_dict