Merge pull request #23 from LunchHunter/un-double-data

Fix `data-` prefix duplication
This commit is contained in:
Bodil Stokke 2018-12-06 17:00:13 +00:00 committed by GitHub
commit 5acffb917f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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());
}