Skip to content

Fix HTML parser treating an empty upload as a missing binary - #17904

Merged
yuzhichang merged 1 commit into
infiniflow:mainfrom
devYRPauli:fix/html-parser-empty-binary
Aug 23, 2026
Merged

yuzhichang merged 1 commit into
infiniflow:mainfrom
devYRPauli:fix/html-parser-empty-binary

Conversation

@devYRPauli

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

RAGFlowHtmlParser.__call__ chose the binary branch with if binary:, which is falsy for an empty bytes object as well as for None. A zero-byte .html upload therefore fell through to the file-path branch and called open(fnm, ...).

Every caller passes a logical file name alongside the payload (HtmlParser()(filename, binary) in rag/app/book.py, laws.py, naive.py, one.py, and rag/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:

before:  normal upload -> OK, 1 section(s): ['hello']
         0-byte upload -> FileNotFoundError: [Errno 2] No such file or directory: 'page.html'

after:   normal upload -> OK, 1 section(s): ['hello']
         0-byte upload -> OK, 0 section(s): []

The two sibling decode sites already use the None check: deepdoc/parser/utils.py in get_text, and deepdoc/parser/epub_parser.py, which additionally raises an explicit "Empty EPUB binary payload" error for this case.

find_codec(b"") is safe: chardet.detect returns confidence 0, the codec loop decodes the empty payload on its first candidate, and b"".decode(..., errors="ignore") gives "", which parser_txt accepts.

Non-empty payloads take the same path as before, so there is no behaviour change for normal uploads.

Type of change

  • Bug Fix (non-breaking change which fixes an issue)

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.
@dosubot dosubot Bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Aug 5, 2026
@coderabbitai

coderabbitai Bot commented Aug 5, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The HTML parser now checks whether binary is None before decoding. Empty byte strings therefore use the binary decoding path.

Changes

HTML parser input handling

Layer / File(s) Summary
Binary input presence check
deepdoc/parser/html_parser.py
RAGFlowHtmlParser.__call__ now distinguishes empty binary input from absent input before decoding.

Estimated code review effort: 1 (Trivial) | ~2 minutes

Poem

A rabbit checks the bytes with care,
Empty ones now travel there.
None alone means “nothing sent,”
The parser follows the intent.
Hop, hop—clean input flow!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the fix for empty uploads in the HTML parser.
Description check ✅ Passed The description explains the problem, affected behavior, verification results, and change type in sufficient detail.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Warning

Review ran into problems

🔥 Problems

Git: Failed to clone repository. Please run the @coderabbitai full review command to re-trigger a full review. If the issue persists, set path_filters to include or exclude specific files.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between ae8cfd4 and 1f0b585.

📒 Files selected for processing (1)
  • deepdoc/parser/html_parser.py

Comment on lines +39 to 41
if binary is not None:
encoding = find_codec(binary)
txt = binary.decode(encoding, errors="ignore")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📐 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

@JinHai-CN
JinHai-CN requested a review from xugangqiang August 19, 2026 07:00
@xugangqiang xugangqiang added the ci Continue Integration label Aug 19, 2026
@xugangqiang

Copy link
Copy Markdown
Contributor

@yuzhichang LGTM

@codecov

codecov Bot commented Aug 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 90.65%. Comparing base (ae8cfd4) to head (1f0b585).
⚠️ Report is 452 commits behind head on main.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants