Repository navigation
Fix HTML parser treating an empty upload as a missing binary - #17904
Conversation
RAGFlowHtmlParser selected the binary branch with a truthy check, so a zero-byte upload took the file-path branch instead. The callers pass a logical file name rather than a path on disk, so that branch raised FileNotFoundError instead of parsing the empty document. Check for None like deepdoc/parser/utils.py and epub_parser.py already do. An empty payload now decodes to an empty string and yields no sections; a non-empty payload is unaffected.
📝 WalkthroughWalkthroughThe HTML parser now checks whether ChangesHTML parser input handling
Estimated code review effort: 1 (Trivial) | ~2 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@deepdoc/parser/html_parser.py`:
- Around line 39-41: Add a debug log in the binary-handling flow around
find_codec and decode, specifically when binary == b"", indicating that the
parser accepted an empty binary payload without including payload content;
preserve the existing decoding behavior for all binary values.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: bcd55fca-b94a-4303-8fe9-e6fc2c71696b
📒 Files selected for processing (1)
deepdoc/parser/html_parser.py
| if binary is not None: | ||
| encoding = find_codec(binary) | ||
| txt = binary.decode(encoding, errors="ignore") |
There was a problem hiding this comment.
📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win
Add a debug log for the empty-binary flow.
When binary == b"", log that the parser accepted an empty binary payload. Do not log payload content.
As per coding guidelines, "**/*.py: Add logging for new flows".
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@deepdoc/parser/html_parser.py` around lines 39 - 41, Add a debug log in the
binary-handling flow around find_codec and decode, specifically when binary ==
b"", indicating that the parser accepted an empty binary payload without
including payload content; preserve the existing decoding behavior for all
binary values.
Source: Coding guidelines
|
@yuzhichang LGTM |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #17904 +/- ##
==========================================
- Coverage 94.56% 90.65% -3.91%
==========================================
Files 10 10
Lines 717 717
Branches 118 118
==========================================
- Hits 678 650 -28
- Misses 25 39 +14
- Partials 14 28 +14 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
What problem does this PR solve?
RAGFlowHtmlParser.__call__chose the binary branch withif binary:, which is falsy for an emptybytesobject as well as forNone. A zero-byte.htmlupload therefore fell through to the file-path branch and calledopen(fnm, ...).Every caller passes a logical file name alongside the payload (
HtmlParser()(filename, binary)inrag/app/book.py,laws.py,naive.py,one.py, andrag/flow/parser/parser.py), not a path that exists on disk, so that branch raises instead of parsing the empty document.Verified against the parser on current main:
The two sibling decode sites already use the
Nonecheck:deepdoc/parser/utils.pyinget_text, anddeepdoc/parser/epub_parser.py, which additionally raises an explicit "Empty EPUB binary payload" error for this case.find_codec(b"")is safe:chardet.detectreturns confidence 0, the codec loop decodes the empty payload on its first candidate, andb"".decode(..., errors="ignore")gives"", whichparser_txtaccepts.Non-empty payloads take the same path as before, so there is no behaviour change for normal uploads.
Type of change