utkarshkukreti / markup.rs

A blazing fast, type-safe template engine for Rust.
Apache License 2.0
350 stars 14 forks source link

Using `Render` trait for attribute values makes it easy to generate invalid HTML #28

Closed utkarshkukreti closed 1 year ago

utkarshkukreti commented 1 year ago

(Posting this here since I don't have time to fix this right now.)

Attribute values are currently rendered using the same Render trait that full templates use, which makes it easy to generate invalid markup:

markup::define! {
    A { #a {} }
    B { div[a = A {}] {} }
}

fn main() {
    println!("{}", B {});
}

=>

<div a="<div id="a"></div>"></div>

I think there should be a separate trait (that probably inherits markup::Render) for things that are allowed to be in attribute values and it should only be implemented by simple values like numbers, strings, booleans, and options that wrap them, and not templates defined by markup::define! or markup::new!.