Skip to content

Detect HTML in partial reads#153

Open
oiahoon wants to merge 1 commit into
rails:mainfrom
oiahoon:fix/html-partial-read-detection
Open

Detect HTML in partial reads#153
oiahoon wants to merge 1 commit into
rails:mainfrom
oiahoon:fix/html-partial-read-detection

Conversation

@oiahoon

@oiahoon oiahoon commented Jul 14, 2026

Copy link
Copy Markdown

Summary

  • detect HTML in leading-byte reads when a UTF-8 BOM, XML declaration, or HTML comments precede the doctype or html element
  • keep the trailing </html> signal and require a real tag-name boundary
  • cover the 4 KiB partial-read shape used by Active Storage, including a custom-element negative boundary

This removes the dependency on seeing the end of a document when only its first bytes are available.

Fixes #152.

Validation

  • bundle exec ruby -Itest test/magic_test.rb -n '/partial|custom/' (2 tests, 13 assertions)
  • bundle exec rake (454 tests, 934 assertions)
  • ruby -c lib/marcel/mime_type/definitions.rb
  • ruby -c test/magic_test.rb
  • gem build marcel.gemspec
  • git diff --check

Allow bounded start detection after a UTF-8 BOM, XML declaration, or HTML comments so leading-byte consumers do not depend on the closing tag. Preserve tag-name boundaries and add focused regressions.
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.

#146's end-of-document HTML check misses partial reads (e.g. Active Storage's 4 KB identify chunk)

1 participant