feat(file): let the file name offer a type no content probe can find - #814
Merged
Conversation
`FileType::markdown` was unreachable by detection: it has no signature, and a content probe for it is a probe for "prose with occasional punctuation", so `detect_by_content` is false and `list_file_types` never offered it. A `.md` came back as `text_file` and the caller had to already know. The name is at the boundary and was being thrown away — `abstract::File` already carries `disk_path`. `file_type_by_name` reads the extension off it and offers the type when the table says no probe can produce it, once the bytes have decoded as text. A name only ever adds a candidate: a `.md` holding a zip is still a zip, and `File::from_memory` has no name, so it still needs `FileType::markdown`. Closes #760. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UDi21mwuKRGvGiFcGwETtS
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.
🤖 Generated with Claude Code
Closes #760.
The gap
FileType::markdownwas the one document format detection could never reach.detect_by_contentis false for it — correctly, since CommonMark has nosignature and every plain text file is valid markdown — so
list_file_typesnever offered it and a
.mdcame back astext_file. Worse, a.mdthathappened to parse as CSV was offered as CSV.
Meanwhile the name was already at the boundary and thrown away:
abstract::File::disk_path()has carried it all along.The change
Option (2) from the issue, which turned out to need no new plumbing.
open_strategy::file_type_by_namereads the extension offdisk_path()andreturns the type only when the table says no content probe can produce it
(
detect_by_content == false). Both detection paths consult it once the byteshave decoded as text:
list_file_typesappends it last, so the preference path's reverse tries itfirst — a
.mdnow lists[text_file, …, markdown].open_filetries it ahead of the csv/json/xml probes, so a markdown filethat parses as CSV stays markdown.
A name never claims bytes: a
.mdholding a zip is still a zip, andFile::from_memoryhas no name, so it still needsFileType::markdown.Verified
New
odr.types_mdandodr.a_misnamed_file_is_what_its_bytes_are.FileTypeCapabilities.declaration_matches_the_enginesheld the old invariant —"whatever detection sees, the table has to admit to" — and now admits the
name-offered type too; that test failing was the observable change the issue
predicted.
Full suite 1420 passed / 6 pre-existing skips. Reference output byte-identical
(
HtmlOutputTestspinsas_file_type, so it never went through detection).Changed TU re-checked under
-Werrorand clang-tidy.