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

wp.i18n.esc_html__() version? XSS? #12220

Closed
manake opened this issue Nov 22, 2018 · 3 comments
Closed

wp.i18n.esc_html__() version? XSS? #12220

manake opened this issue Nov 22, 2018 · 3 comments
Labels
[Package] i18n /packages/i18n [Type] Question Questions about the design or development of the editor.

Comments

@manake
Copy link

manake commented Nov 22, 2018

Is wp.i18n.esc_html__() version planned?
How to achieve this?
Is this necessary or some escaping is already happening?

@swissspidy swissspidy added [Type] Question Questions about the design or development of the editor. [Package] i18n /packages/i18n labels Nov 22, 2018
@swissspidy
Copy link
Member

This is not really needed in a React / JavaScript context as all the strings would be escaped anyway (unless you use something dangerouslySetInnerHTML)

@manake
Copy link
Author

manake commented Nov 22, 2018

Nice.

  1. What does it mean "unless you use something dangerouslySetInnerHTML"?
  2. Does it mean that in JavaScript context writing __('Some string with <a href="https://example.com/">a link</a> in it,', 'text-domain'); would not create a link? Ok, that makes sense. Perhaps wp.i18n.sprintf should be used to create text with links then (I didn't try this yet).

@swissspidy
Copy link
Member

Does it mean that in JavaScript context writing __('Some string with <a href="https://example.com/">a link</a> in it', 'text-domain'); would not create a link?

Correct. sprintf won't help you there. You'd need to use dangerouslySetInnerHTML to directly write HTML. Otherwise < and > get escaped.

See also #9846 for a discussion about this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] i18n /packages/i18n [Type] Question Questions about the design or development of the editor.
Projects
None yet
Development

No branches or pull requests

2 participants