Skip to content

Fix/title encoding bug#19187

Merged
glendaviesnz merged 5 commits intomasterfrom
fix/title-encoding-bug
Dec 18, 2019
Merged

Fix/title encoding bug#19187
glendaviesnz merged 5 commits intomasterfrom
fix/title-encoding-bug

Conversation

@glendaviesnz
Copy link
Copy Markdown
Contributor

@glendaviesnz glendaviesnz commented Dec 17, 2019

Description

The encoding that was recently added to the post title block works fine on standalone wp installs, but not on wpcom - Automattic/wp-calypso#38362 - this is because for some reason wpcom adds leading zeros to the html entity codes, and lodash unescape does not account for this.

Switching from the lodash unescape to WordPress decodeEntities resolves the issue without causing any problems that I can see.

How has this been tested?

Tested manually, and also added an additional unit test to make sure decodeEntities accounts for leading zeros.

Screenshots

Before:

encode-before

After:

encode-after

Types of changes

Change string decoding method

Fixes Automattic/wp-calypso#38362

id={ `post-title-${ instanceId }` }
className="editor-post-title__input"
value={ unescape( title ) }
value={ decodeEntities( title ) }
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are the differences in implementation? Can we add a unit test to catch the broken case here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some level of filtering on wpcom converts #39; to #039;. lodash unescape only looks for an exact match of #39;. WP decodeEntities on the other hand, doesn't search for specific entity strings, it just throws everything into a temporary text field in the dom and then extracts, so relies entirely on the browsers own encoding/decoding, which handles both #39; and #039;

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added an additional test to cover this variation in entity codes.

@glendaviesnz glendaviesnz requested a review from aduth as a code owner December 18, 2019 00:51
id={ `post-title-${ instanceId }` }
className="editor-post-title__input"
value={ unescape( title ) }
value={ decodeEntities( title ) }
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder a bit about the corresponding escape which happens in the onUpdate dispatch below. In truth, I'm not actually sure why it's needed at all. But at least previously, there was a duality between unescape and escape which is no longer guaranteed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I wonder why we added only decodeEntities in #7977. I think an upstream patch to lodash (as including leading zeros is okay), and dependency update would work too, but I think I'm missing some context here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder a bit about the corresponding escape

Yes, it would be good to update that to an internal encoding method once one is available.

Copy link
Copy Markdown
Contributor

@gwwar gwwar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think changes here make sense @glendaviesnz 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Gutenberg: Post Titles with Apostrophe Turn to ' When Published

4 participants