Skip to content

Commit

Permalink
fix: Dont assume ascii in remove_markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
Waqar144 committed Dec 18, 2023
1 parent 0ed815f commit 5318e89
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion crates/ide/src/markdown_remove.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ pub(crate) fn remove_markdown(markdown: &str) -> String {
}
}

if let Some(p) = out.rfind(|c| c != '\n') {
if let Some(mut p) = out.rfind(|c| c != '\n') {
while !out.is_char_boundary(p + 1) {
p += 1;
}
out.drain(p + 1..);
}

Expand Down Expand Up @@ -153,4 +156,10 @@ book] or the [Reference].
For more information on the various types of functions and how they're used, consult the Rust book or the Reference."#]].assert_eq(&res);
}

#[test]
fn on_char_boundary() {
expect!["a┘"].assert_eq(&remove_markdown("```text\na┘\n```"));
expect!["وقار"].assert_eq(&remove_markdown("```\nوقار\n```\n"));
}
}

0 comments on commit 5318e89

Please sign in to comment.