Fix `data-` prefix duplication

The `data-` prefix is being duplicated, such that `data-foo="bar"` is
being rendered as `data-data-foo="bar"`.

This change removes the prefix at the `Element` level, and leaves its
addition at the `Display` level, causing it to be rendered correctly.
This commit is contained in:
lunchhunter 2018-12-04 16:23:03 -08:00
parent 4c49aca99f
commit c2584878a5
No known key found for this signature in database
GPG Key ID: 82550B72704ABBC6
2 changed files with 11 additions and 1 deletions

View File

@ -77,7 +77,7 @@ fn extract_data_attrs(attrs: &mut StringyMap<Ident, TokenTree>) -> StringyMap<St
let prefix = "data_";
if key_name.starts_with(prefix) {
let value = attrs.remove(&key).unwrap();
data.insert(format!("data-{}", &key_name[prefix.len()..]), value);
data.insert(key_name[prefix.len()..].to_string(), value);
}
}
data

View File

@ -410,3 +410,13 @@ declare_elements!{
width: String, // FIXME size
} in [FlowContent, PhrasingContent] with PhrasingContent;
}
#[test]
fn test_data_attributes() {
use crate as typed_html;
use crate::dom::DOMTree;
let frag: DOMTree<String> = html!(<div data-id="1234">"Boo!"</div>);
assert_eq!("<div data-id=\"1234\">Boo!</div>", frag.to_string());
}