Skip to content

Commit c7dfdf8

Browse files
committed
fix: html escape bug with utf-8 characters
1 parent 7ee436f commit c7dfdf8

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

crates/engarde/src/raw.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ fn html_escape(input: &str) -> String {
4444
let mut result = String::new();
4545
let mut last = 0;
4646
let mut skip = 0;
47-
for (i, c) in input.chars().enumerate() {
47+
for (i, c) in input.char_indices() {
4848
if skip > 0 {
4949
skip -= 1;
5050
continue;
@@ -99,4 +99,12 @@ mod test {
9999
let output = syntax.format(CODEBLOCK, Some("rust"), Some(""));
100100
assert_eq!(output, CODEBLOCK_RENDERED.to_string());
101101
}
102+
103+
const CODEBLOCK2: &str = r#"// comment with utf-8 你好 😎 <hello>"#;
104+
105+
#[test]
106+
fn codeblock_renders_rust_utf8() {
107+
let syntax = Raw::new();
108+
let _output = syntax.format(CODEBLOCK2, Some("rust"), Some(""));
109+
}
102110
}

0 commit comments

Comments
 (0)