-
-
Notifications
You must be signed in to change notification settings - Fork 94
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
Don't escape HTML &-entities in literal text #176
Comments
Moving this to https://github.com/preactjs/preact-render-to-string |
This actually is an HTM issue. JSX converts html-encoded entities to UTF8 (see example), it's not part of VDOM rendering. Because of this, I think developit/htm#76 describes this issue pretty well though. From a Preact standpoint, neither the client-side renderer nor the server-side renderer should be handling this, since both treat JSXText as string literals (to match all other VDOM libraries). It would be too strange/broken if ~~ For context on the HTM issue: the reason this hasn't been done is because HTML entity decoding is disproportionately expensive for no material gain. Entity decoding can only be implemented using a character mapping that is larger than HTM and Preact combined (along with a decent bit of conversion logic). Here's the mapping Babel's JSX transform uses: When running in a browser context, HTM could technically use the DOM to perform this conversion, which is slow but cacheable. Personally though, I'm not a huge fan of any of the approaches. There are two use-cases for HTM decoding HTML entities:
For the second use-case, at some point I would like to extract the old HTM 1 codebase, which was built on DOMParser and actually set out to cater to handling the full spectrum of HTML use-cases. In the meantime, |
I'm not very good at English, so I don't really understand what's going on, but I'm having trouble escaping the following results. Code:
Result:
Is there an option to cancel the escaping? My workaround: |
Should this be occurring in props too? For example, render(h('div', { class: 'flex(& col)' }));
// Results in
<div class="flex(& col)"></div> which is rather unexpected. Edit: Seems React does it too. Interesting. I thought props shouldn't be an issue. |
any updates on this? |
bump |
[Closing out issues I authored that appear to be stagnant.] |
@broofa please re-open. |
@torchsmith: No. This issue is 2+ years old and conversation petered out at [in essence], "Won't fix". If you want this reopened, make the case for that to the maintainers. I've moved on to other things and have unsubscribed from this issue. |
I fixed it with: |
See also developit/htm#76
According to the JSX docs, "You can insert HTML entities within literal text in JSX", but this does not appear to work because of how &'s are escaped in the encodeEntities() method.
Could this method be made to ignore &'s that are part of valid html character entities? I could put a PR together, but want to get a sense of how receptive you are to this. (And I suspect I may be missing other, important requirements.)
The text was updated successfully, but these errors were encountered: