Skip to content

Commit

Permalink
Relax attribute escaping. Fixes #26
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanKingston authored and bodil committed May 28, 2019
1 parent 9c81041 commit 1588f30
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
4 changes: 2 additions & 2 deletions macros/src/declare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ impl Declare {
for (attr_name, _, attr_str) in self.attrs() {
print_attrs.extend(quote!(
if let Some(ref value) = self.attrs.#attr_name {
let value = ::htmlescape::encode_attribute(&value.to_string());
let value = crate::escape_html_attribute(value.to_string());
if !value.is_empty() {
write!(f, " {}=\"{}\"", #attr_str, value)?;
}
Expand All @@ -355,7 +355,7 @@ impl Declare {
#print_attrs
for (key, value) in &self.data_attributes {
write!(f, " data-{}=\"{}\"", key,
::htmlescape::encode_attribute(&value))?;
crate::escape_html_attribute(value.to_string()))?;
}
write!(f, "{}", self.events)?;
#print_children
Expand Down
8 changes: 8 additions & 0 deletions typed-html/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,3 +227,11 @@ impl OutputType for String {
type EventTarget = ();
type EventListenerHandle = ();
}

pub fn escape_html_attribute(html_attr: String) -> String {
// Even though the code is quoting the variables with a double quote, escape all known quoting chars
html_attr
.replace("\"", """)
.replace("'", "'")
.replace("`", "`")
}

0 comments on commit 1588f30

Please sign in to comment.