Skip to content

Commit 1588f30

Browse files
jonathanKingstonbodil
authored andcommitted
Relax attribute escaping. Fixes bodil#26
1 parent 9c81041 commit 1588f30

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

macros/src/declare.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ impl Declare {
337337
for (attr_name, _, attr_str) in self.attrs() {
338338
print_attrs.extend(quote!(
339339
if let Some(ref value) = self.attrs.#attr_name {
340-
let value = ::htmlescape::encode_attribute(&value.to_string());
340+
let value = crate::escape_html_attribute(value.to_string());
341341
if !value.is_empty() {
342342
write!(f, " {}=\"{}\"", #attr_str, value)?;
343343
}
@@ -355,7 +355,7 @@ impl Declare {
355355
#print_attrs
356356
for (key, value) in &self.data_attributes {
357357
write!(f, " data-{}=\"{}\"", key,
358-
::htmlescape::encode_attribute(&value))?;
358+
crate::escape_html_attribute(value.to_string()))?;
359359
}
360360
write!(f, "{}", self.events)?;
361361
#print_children

typed-html/src/lib.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,3 +227,11 @@ impl OutputType for String {
227227
type EventTarget = ();
228228
type EventListenerHandle = ();
229229
}
230+
231+
pub fn escape_html_attribute(html_attr: String) -> String {
232+
// Even though the code is quoting the variables with a double quote, escape all known quoting chars
233+
html_attr
234+
.replace("\"", """)
235+
.replace("'", "'")
236+
.replace("`", "`")
237+
}

0 commit comments

Comments
 (0)