Skip to content

Commit 8b2b343

Browse files
committed
Ensure unhighlighted code is still escaped
1 parent b42137d commit 8b2b343

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/web/highlight.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,16 @@ pub fn with_lang(lang: Option<&str>, code: &str) -> String {
7373
} else {
7474
log::error!("failed while highlighting code: {err:?}");
7575
}
76-
code.to_owned()
76+
tera::escape_html(code)
7777
}
7878
}
7979
}
8080

8181
#[cfg(test)]
8282
mod tests {
83-
use super::{select_syntax, try_with_lang, LimitsExceeded, CODE_SIZE_LIMIT, LINE_SIZE_LIMIT};
83+
use super::{
84+
select_syntax, try_with_lang, with_lang, LimitsExceeded, CODE_SIZE_LIMIT, LINE_SIZE_LIMIT,
85+
};
8486

8587
#[test]
8688
fn custom_filetypes() {
@@ -107,4 +109,11 @@ mod tests {
107109
assert!(is_limited("a\n".repeat(CODE_SIZE_LIMIT)));
108110
assert!(is_limited("aa".repeat(LINE_SIZE_LIMIT)));
109111
}
112+
113+
#[test]
114+
fn limited_escaped() {
115+
let text = "<p>\n".to_string() + "aa".repeat(LINE_SIZE_LIMIT).as_str();
116+
let highlighted = with_lang(Some("toml"), &text);
117+
assert!(highlighted.starts_with("&lt;p&gt;\n"));
118+
}
110119
}

0 commit comments

Comments
 (0)