Skip to content

Commit

Permalink
fix(HTML): Escape strings
Browse files Browse the repository at this point in the history
  • Loading branch information
nokome committed Jun 14, 2021
1 parent 7507118 commit e17d0a3
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions rust/src/methods/encode_html.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,19 +206,21 @@ impl ToHtml for String {
}

impl ToHtml for Vec<Primitive> {
fn to_html(&self, _context: &Context) -> String {
fn to_html(&self, context: &Context) -> String {
let json = serde_json::to_string(self).unwrap_or_else(|_| "".into());
format!(
r#"<span itemtype="http://schema.stenci.la/Array">{content}</span>"#,
content = serde_json::to_string(self).unwrap_or_else(|_| "".into())
r#"<code itemtype="http://schema.stenci.la/Array">{content}</code>"#,
content = json.to_html(context) // Ensure string is escaped
)
}
}

impl ToHtml for BTreeMap<String, Primitive> {
fn to_html(&self, _context: &Context) -> String {
fn to_html(&self, context: &Context) -> String {
let json = serde_json::to_string(self).unwrap_or_else(|_| "".into());
format!(
r#"<span itemtype="http://schema.stenci.la/Object">{content}</span>"#,
content = serde_json::to_string(self).unwrap_or_else(|_| "".into())
r#"<code itemtype="http://schema.stenci.la/Object">{content}</code>"#,
content = json.to_html(context) // Ensure string is escaped
)
}
}
Expand Down

0 comments on commit e17d0a3

Please sign in to comment.