Skip to content

fix (#6586): Set a length limit #6600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

algosul
Copy link

@algosul algosul commented Jul 9, 2025

Fixes #6586

After formatting, the line_start may be longer than line. For example, "> >" (3 characters) will become "> > " (4 characters) after formatting.

@ytmimi
Copy link
Contributor

ytmimi commented Jul 9, 2025

Can we prevent "> >" from getting reformatted as "> > "? Based on your comment that seems like the root of the problem, but the current solution tries to resolve it after the fact, or am I missing something?

@algosul
Copy link
Author

algosul commented Jul 9, 2025

Can we prevent "> >" from getting reformatted as "> > "? Based on your comment that seems like the root of the problem, but the current solution tries to resolve it after the fact, or am I missing something?我们能否防止 “> >” 被重新格式化为 “> > ”?根据您的评论,这似乎是问题的根源,但当前的解决方案试图在事后解决它,还是我遗漏了什么?

I'm very sorry that I didn't explain it clearly.

But this is the best solution I can think of.

In ItemizedBlock::new (approximately 490 lines)

 fn new(line: &str) -> Option<ItemizedBlock> {
    let marker_length = ItemizedBlock::get_marker_length(line.trim_start())?;
    let space_to_marker = line.chars().take_while(|c| c.is_whitespace()).count();
    let mut indent = space_to_marker + marker_length;
    let mut line_start = " ".repeat(indent);

    // Markdown blockquote start with a "> "
    if line.trim_start().starts_with('>') {
        // remove the original +2 indent because there might be multiple nested block quotes
        // and it's easier to reason about the final indent by just taking the length
        // of the new line_start. We update the indent because it effects the max width
        // of each formatted line.
        line_start = itemized_block_quote_start(line, line_start, 2); // <--- Formatting has been applied here.
        indent = line_start.len().min(line.len()); // <--- Changed line
    }
    Some(ItemizedBlock {
        lines: vec![line[indent..].to_string()], // <--- The line that causes panic: `line[indent..]` might be access violation
        indent,
        opener: line[..indent].to_string(),
        line_start,
    })
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[bug] wrap_comments
3 participants