Skip to content

Commit 6e914c1

Browse files
committed
to_markdown: fix another crash on non-ascii
Related-to: GH-170.
1 parent add76bd commit 6e914c1

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

mdast_util_to_markdown/src/state.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,12 @@ impl<'a> State<'a> {
535535
};
536536
}
537537

538+
// Some of the operations above seem to end up right in a utf8 boundary
539+
// (see GH-170 for more info).
540+
// Move back.
541+
while !value.is_char_boundary(start) {
542+
start -= 1;
543+
}
538544
result.push_str(&escape_backslashes(&value[start..end], config.after));
539545

540546
result

mdast_util_to_markdown/tests/paragraph.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,17 @@ fn paragraph() {
104104
"a\t&#x9;\n&#x9;\tb\n",
105105
"should encode spaces around line endings in paragraphs"
106106
);
107+
108+
assert_eq!(
109+
to(&Node::Paragraph(Paragraph {
110+
children: vec![Node::Text(Text {
111+
value: String::from("я_я"),
112+
position: None
113+
})],
114+
position: None
115+
}))
116+
.unwrap(),
117+
"я&#x44F;я\n",
118+
"should support escaping around non-ascii"
119+
);
107120
}

0 commit comments

Comments
 (0)