about summary refs log tree commit diff
diff options
context:
space:
mode:
authorWaqar Ahmed <waqar.17a@gmail.com>2023-12-19 01:27:36 +0500
committerWaqar Ahmed <waqar.17a@gmail.com>2023-12-19 01:27:36 +0500
commit5318e89b8a77de72d478be13d7ae0eea3f397629 (patch)
treead7b6243c0b64951badb98209ce638c30b55eab4
parent0ed815faca2c408803cb2724c288ca8a2094e58b (diff)
downloadrust-5318e89b8a77de72d478be13d7ae0eea3f397629.tar.gz
rust-5318e89b8a77de72d478be13d7ae0eea3f397629.zip
fix: Dont assume ascii in remove_markdown
Fixes #16142
-rw-r--r--crates/ide/src/markdown_remove.rs11
1 files changed, 10 insertions, 1 deletions
diff --git a/crates/ide/src/markdown_remove.rs b/crates/ide/src/markdown_remove.rs
index 718868c8747..74cb320c027 100644
--- a/crates/ide/src/markdown_remove.rs
+++ b/crates/ide/src/markdown_remove.rs
@@ -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..);
     }
 
@@ -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"));
+    }
 }