Skip to content

Commit 5318e89

Browse files
committed
fix: Dont assume ascii in remove_markdown
Fixes rust-lang#16142
1 parent 0ed815f commit 5318e89

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

crates/ide/src/markdown_remove.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@ pub(crate) fn remove_markdown(markdown: &str) -> String {
2525
}
2626
}
2727

28-
if let Some(p) = out.rfind(|c| c != '\n') {
28+
if let Some(mut p) = out.rfind(|c| c != '\n') {
29+
while !out.is_char_boundary(p + 1) {
30+
p += 1;
31+
}
2932
out.drain(p + 1..);
3033
}
3134

@@ -153,4 +156,10 @@ book] or the [Reference].
153156
154157
For more information on the various types of functions and how they're used, consult the Rust book or the Reference."#]].assert_eq(&res);
155158
}
159+
160+
#[test]
161+
fn on_char_boundary() {
162+
expect!["a┘"].assert_eq(&remove_markdown("```text\na┘\n```"));
163+
expect!["وقار"].assert_eq(&remove_markdown("```\nوقار\n```\n"));
164+
}
156165
}

0 commit comments

Comments
 (0)