-
Notifications
You must be signed in to change notification settings - Fork 14
Open
Description
Bug
When mdsh processes a file in-place that contains no mdsh tags, it corrupts the file on repeated runs by deleting lines from the end.
Reproduction
Build from source
nix develop --command cargo build --releaseCase 1: File with trailing newline
Trailing newline stripped on first run, last line deleted on second run
nix develop --command bash -c 'printf "# No mdsh tags\n\ntext\n" > /tmp/test.md && ./target/release/mdsh --input /tmp/test.md && diff <(printf "# No mdsh tags\n\ntext\n") /tmp/test.md'Run again — "text" is now gone
nix develop --command bash -c './target/release/mdsh --input /tmp/test.md && diff <(printf "# No mdsh tags\n\ntext\n") /tmp/test.md'Case 2: File without trailing newline
Last line dropped on first run
nix develop --command bash -c 'printf "# No mdsh tags\n\ntext" > /tmp/test2.md && ./target/release/mdsh --input /tmp/test2.md && diff <(printf "# No mdsh tags\n\ntext") /tmp/test2.md'Root cause
Two interacting issues in src/main.rs:
trim_ascii_end(applied on in-place writes) strips all trailing ASCII whitespace including\n, removing the file's trailing newline.- The parser's catch-all in
src/parser.rsmatches lines with(take_until("\n"), newline), which requires a trailing\n. Lines without one are silently dropped.
This creates a cascading failure: each run strips the trailing newline, causing the next run to drop the now-unterminated last line.
Expected behavior
Running mdsh on a file with no mdsh tags should leave it unchanged, regardless of whether it has a trailing newline.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels