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

The enter_title_here and escaped HTML might display encoded characters #4933

Closed
afercia opened this issue Feb 7, 2018 · 4 comments · Fixed by #5557
Closed

The enter_title_here and escaped HTML might display encoded characters #4933

afercia opened this issue Feb 7, 2018 · 4 comments · Fixed by #5557
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience Good First Issue An issue that's suitable for someone looking to contribute for the first time [Type] Bug An existing feature does not function as intended

Comments

@afercia
Copy link
Contributor

afercia commented Feb 7, 2018

See #4059 / #4042

Several plugins (and themes...) use the enter_title_here filter to display their own title "placeholder" (note: in the classic editor it's actually a <label> element) for their custom post types. When the passed string contains a special character and the string gets escaped, The placeholder used in Gutenberg displays an encoded character.

For example, see in the screenshot below the "Add New Testimonial` screen from Jetpack:

screen shot 2018-02-07 at 14 59 34

Worth also noting that translations might add quotes or ampersands etc. to the original English strings.

Escaping is a good practice for HTML but an encoded character is just displayed "as is" in Gutenberg. Ideally, Gutenberg should handle these cases in some way.

@mtias mtias added the [Feature] Extensibility The ability to extend blocks or the editing experience label Feb 8, 2018
@gziolo gziolo added the [Type] Bug An existing feature does not function as intended label Feb 28, 2018
@gziolo
Copy link
Member

gziolo commented Mar 10, 2018

It should be also tested with the newly introduced filter write_your_story.

@aduth
Copy link
Member

aduth commented Mar 10, 2018

This can be resolved by using decodeEntities from utils:

import { decodeEntities } from '@wordpress/utils';

decodeEntities( 'Enter the customer&#039;s name' );
// "Enter the customer's name"

@aduth aduth added the Good First Issue An issue that's suitable for someone looking to contribute for the first time label Mar 10, 2018
@aduth
Copy link
Member

aduth commented Mar 12, 2018

Alternatively, we could ensure that the strings are decoded server-side before reaching the client with a late filter to html_entity_decode:

add_filter( 'enter_title_here', 'html_entity_decode', 20 );

This is nice in that it's automatic, and doesn't require explicitly whitelisting strings to be decoded.

However, it only works because we trust in React's assignment of attributes to not allow for XSS. Naive usage via innerHTML could be dangerous with automatic decoding.

Also relevant for localization, since as discussed at #5557 (comment), this same issue applies if we start to decode entities in translation strings automatically (#3301 is a good problematic example). I don't think we'd want to explicitly call decodeEntities on every usage of a translated string. If we could be confident it's in a React context, we could automate it. Maybe even with a component like:

<__>Hello World</__>

cc @jahvi

@aduth
Copy link
Member

aduth commented Mar 13, 2018

Related: #5490

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Extensibility The ability to extend blocks or the editing experience Good First Issue An issue that's suitable for someone looking to contribute for the first time [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants