Repository navigation
fix(filter): don't treat /* inside strings as a block comment - #2415
Closed
luccinmasirika wants to merge 1 commit into
Closed
luccinmasirika wants to merge 1 commit into
luccinmasirika wants to merge 1 commit into
Conversation
The minimal filter opened a block comment whenever a line *contained*
`/*`, so a `/*` in a string literal or a trailing comment dropped the
whole line — and if it had no matching `*/`, every following line went
with it until one showed up. A snippet like
let re = "start /*";
let x = 5;
lost both lines.
Match the opening marker with starts_with, like line comments already do,
so only lines that actually begin a block comment get stripped. Code with
`/*` in a string or trailing comment is kept.
Closes rtk-ai#2385
Contributor
Author
|
Closing as a duplicate — #2397 already fixes this with the same line-start detection and predates this PR. Deferring to it. Thanks @hgunduzoglu! |
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.
Summary
Fixes #2385. The minimal code filter dropped real code lines that happened to contain
/*.MinimalFilteropened a block comment whenever a line contained/*(trimmed.contains(start)), so:/*inside a string literal or a trailing comment dropped the whole line;*/, every following line was dropped too until one showed up.Fix
Match the opening marker with
starts_withinstead ofcontains— the same way line comments are already detected one block below. Only a line that actually begins with/*opens a block comment; doc blocks (/**) are still preserved, and genuine standalone/multi-line block comments are still stripped.Tests
test_minimal_filter_keeps_code_with_block_comment_markers— code with/*in a string / trailing comment is preserved (fails on the oldcontainsversion, passes now).test_minimal_filter_still_strips_block_comments— standalone and multi-line block comments are still removed.Verified end-to-end with the issue's reproduction:
(only the standalone
/* ... */line is stripped; no code is lost).Pre-commit gate (
cargo fmt --all && cargo clippy --all-targets && cargo test) passes; clippy is clean.