diff --git a/crates/rustwell/src/export/html.rs b/crates/rustwell/src/export/html.rs index b70343f..7c5d0ea 100644 --- a/crates/rustwell/src/export/html.rs +++ b/crates/rustwell/src/export/html.rs @@ -119,7 +119,10 @@ impl HtmlExporter { }, self.format_rich_string(slug), if let Some(x) = number { - format!(r#"{x}"#) + format!( + r#"{}"#, + Self::encode_special_html_characters(&x) + ) } else { String::new() }, @@ -223,7 +226,10 @@ impl HtmlExporter { if element.is_italic() { "" } else { "" }, if element.is_bold() { "" } else { "" }, ); - format!("{prepend}{}{append}", element.text) + format!( + "{prepend}{}{append}", + Self::encode_special_html_characters(&element.text) + ) } /// Formats the [Vec] of the dialogue into a `html`-[String], combining the @@ -248,4 +254,11 @@ impl HtmlExporter { DialogueElement::Line(s) => format!(r"

{}

", self.format_rich_string(s)), } } + + /// Encodes potentially dangerous patterns in `html` + fn encode_special_html_characters(s: &str) -> String { + s.replace('&', "&") + .replace('<', "<") + .replace('>', ">") + } }