-
Notifications
You must be signed in to change notification settings - Fork 930
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
attributes_escape/1 does not escape ids completely #3465
Comments
I think we need to differentiate between what's allowed in attributes vs. what's allowed to be a valid CSS selector. The only official restriction on IDs in HTML5 is no whitespaces, so this is something we could warn about when we encounter one, but the additional overhead of checking strings for whitespaces might not be worth it. Having a
Can you provide some details? If this is on the JS side, adding a |
The goal of this library is to escape HTML to avoid HTML injection, that's it. Doing per attribute validation would be quite hard because some attributes also depend on the tag. In the case of ID, we do validate integers to avoid common pitfalls (and because it is very cheap to do so!), but it is not our goal or intention to validate all of it. |
The problem is that if there is one element in the HEEX with an invalid id and this element has a |
That's something we are able to fix in LV's js though, right? So more of a LV bug then. |
@ponychicken can you provide an example to reproduce the error in LV? I just tried a button with id "foo/bar" and it worked just fine: <button phx-click="inc">+</button>
<button id="foo/bar" phx-click="dec">-</button> |
The stack:
The heex:
|
@ponychicken what is your LV version? It may have been fixed in more recent ones. |
I was on rc6 and just upgraded to rc7 with the same result |
Ah well in that case it's not a LV bug as you are the one passing the selector. When you said
I thought you were talking about the The correct solution here would be to manually escape the strings before passing them to |
@SteffenDE maybe we should make css_escape part of Phoenix.HTML? Going back to the starting point here. :) |
@ponychicken this will be part of the next I hope that this helps! |
@SteffenDE Thank you <3333 |
I have data from a legacy system. On a few entries in noticed a subtle breakage. I traced it down to attributes_escape/1 not escaping ids sufficiently-
The docs hint that passing a number will throw an error:
But passing the number a string will happily produce output:
Same for whitespace ("An ID attribute's value must not contain ASCII whitespace characters.")
Additionally also characters like "/" are not valid in ids, but the escape function will not escape them as well:
The text was updated successfully, but these errors were encountered: