Skip to content

fix: correct character indexing for non-ASCII strings in markdown escaping #181

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 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion mdast_util_to_markdown/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ impl<'a> State<'a> {
}
start = *position;

let char_at_pos = value.chars().nth(*position);
let char_at_pos = value[*position..].chars().next();
match char_at_pos {
Some('!'..='/') | Some(':'..='@') | Some('['..='`') | Some('{'..='~') => {
if let Some(encode) = &config.encode {
Expand Down
15 changes: 14 additions & 1 deletion mdast_util_to_markdown/tests/paragraph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,20 @@ fn paragraph() {
position: None
}))
.unwrap(),
&#x44F;я\n",
\\_я\n",
"should support escaping around non-ascii"
);

assert_eq!(
to(&Node::Paragraph(Paragraph {
children: vec![Node::Text(Text {
value: String::from("테스트 [테스트] → [테스트]"),
position: None
})],
position: None
}))
.unwrap(),
"테스트 \\[테스트] → \\[테스트]\n",
"should support escaping of a shortcut reference in non-ascii text"
);
}