Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug: PreEscaped into attribute generates invalid HTML #468

Open
Porges opened this issue Jan 29, 2025 · 2 comments
Open

Bug: PreEscaped into attribute generates invalid HTML #468

Porges opened this issue Jan 29, 2025 · 2 comments

Comments

@Porges
Copy link

Porges commented Jan 29, 2025

This is related to #181 but I don't think it has been called out explicitly as a problem there. If you have some Markup/PreEscaped and slot it into an attribute then that is passed on without any further escaping, but Markup is escaped to be valid HTML not to be valid attribute content.

For example:

let title = maud::html! {
    "With " a href="https://example.com" { "a link in it" }
};

let result = maud::html! {
    meta property="og:title" content=(title);
};

println!("{}", result.into_string());

Output:

<meta property="og:title" content="With <a href="https://example.com">a link in it</a>">

There are multiple possible solutions here:

  • either the input needs to be re-escaped for the correct context
  • or putting already-encoded input from the wrong context in should produce an error (since even the escaped version here is going to be dubious, even if it's safe, probably the intent is really to use the equivalent of textContent, but that cannot be decided in advance)
@Porges
Copy link
Author

Porges commented Jan 29, 2025

Ah, looks like this might have been started to be addressed in #460?

@lambda-fairy
Copy link
Owner

Yes this is a known issue. I don't think there's an easy way out of it without context-aware escaping. I'll take a note of it when I work on #322.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants