-
Notifications
You must be signed in to change notification settings - Fork 946
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
Avoid implicit innerHTML assignments #2636
Comments
Thanks. This has also bothered me for a long time too. |
I think a nontrivial fraction of users appreciate being able to do simple styling (bold, italics, colors, etc.) on things like descriptions or checkbox. The widget_selection example is sanitized a few lines above. |
I like this thought. I think the vast majority of cases are served by textContent. It's nice to have some formatting capability when needed, and for backwards compatibility at this point. I think we probably always ought to sanitize in controls, and have the opt-in to using innerHTML. |
Is there anyone willing to push this forward in the next week or so for 8.0? |
If nobody more qualified is available, I can find the time. |
I was hoping to be able to get a chance to work on this but have not been able to carve out any time yet. I agree that a default of sanitizing with an option to skip sanitization would be a reasonable approach. |
Do you think we ought to default to using textContent, or innerHTML with sanitization and perhaps very limited whitelist (like font weight, colors, italics, underline, etc.)? |
On a clean implementation I'd definitely recommend textContent as it avoids surprises when the text happens to contain chars such as |
@zerline - you may be the one I know that is most using formatting in descriptions, so it would be especially great to hear your thoughts. Here is one idea: switch to using textContent by default for descriptions (so no formatting, but no surprises either, just plain text), and have a new |
actually I don't, as my inputs usually have no description ..
From my experience as a user and developer: We sometimes see icons within input descriptions. Or links to a footnote (anchors). Styling options should be accepted too (<i>, <b>, ... and <style>) |
Did #2785 close this? |
Yes- great work here, thanks @zerline! |
Since innerHTML assignments can lead to unintended side effects it should be clear to consumers of these APIs when data may lead to an innerHTML assignment.
An example of an assignment which should probably be clearer:
Potential ways to address this:
From a quick glance, a few places that could be worth changing:
ipywidgets/packages/controls/src/widget_bool.ts
Line 89 in ab54ea0
ipywidgets/packages/controls/src/widget_description.ts
Line 78 in ab54ea0
ipywidgets/packages/controls/src/widget_selection.ts
Line 463 in ab54ea0
ipywidgets/packages/controls/src/widget_string.ts
Line 458 in ab54ea0
The text was updated successfully, but these errors were encountered: