Skip to content

fix(filter): don't treat /* inside strings as a block comment - #2415

Closed
luccinmasirika wants to merge 1 commit into
rtk-ai:developfrom
luccinmasirika:fix/minimal-filter-drops-code-2385
Closed

luccinmasirika wants to merge 1 commit into
rtk-ai:developfrom
luccinmasirika:fix/minimal-filter-drops-code-2385

Conversation

@luccinmasirika

Copy link
Copy Markdown
Contributor

Summary

Fixes #2385. The minimal code filter dropped real code lines that happened to contain /*.

MinimalFilter opened a block comment whenever a line contained /* (trimmed.contains(start)), so:

  • a /* inside a string literal or a trailing comment dropped the whole line;
  • if that line had no matching */, every following line was dropped too until one showed up.
let re = "start /*";   // dropped
let x = 5;             // dropped (still "inside" the phantom comment)

Fix

Match the opening marker with starts_with instead of contains — 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 old contains version, 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:

$ rtk read example.rs --level minimal
const API: &str = "http://example.com/v1"; // endpoint
let re = "start /*";
let pattern = "/* not a comment */";
let x = 5; /* inline note */
fn foo() {}

(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.

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
@CLAassistant

CLAassistant commented Jun 12, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@luccinmasirika

Copy link
Copy Markdown
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!

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.

MinimalFilter silently drops valid code lines containing // or /* anywhere in the line (contains vs starts_with)

2 participants