-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
PlainText block not properly escaping attributes object in db #6181
Comments
Thanks for the report, @dzaikos . I'm not able to reproduce the original issue, given your plugin script. Here is what I see saved in my database:
A couple questions:
|
No. The browser inspector shows everything is fine with respect to the request to save the post. In fact, my original suspicion of it being related to the stringify() call was wrong. When I examine the content of the request in the inspector it actually shows properly escaped data.
No. Just the Twenty Seventeen theme and the Gutenberg plugin (with a stable version of WordPress, as mentioned in my original post). So what I did was litter the WordPress core with debug code to track the POSTed data throughout the entire process. And I've narrowed it down to
With this:
It works every properly everytime. Edit: The Edit 2: So while I should be getting some sleep, I delved further and at the end of it all (because the kses functions are crazy numerous) it appears Now I'm not suggesting we change the WP core, obviously. But hopefully it can give you an idea about why I'm experiencing the issue? |
I believe user role may be a factor here. I was able to reproduce the original issue when saving a post as contributor, but not as administrator. |
Easier steps to reproduce:
Expected: Quote should be escaped. Example (from
|
An alternative option is to entity-encode rather than escape the characters, which shouldn't be subject to unslashing. |
Proposed fix / workaround at #6619 |
Great work! I had Hopefully your pull request fixing the issue can get approved as it seems to work well. |
Issue Overview
When registering a custom block type that uses the PlainText block, the object saved into the
post_content
database field is not a properly escaped JSON object.Steps to Reproduce (for bugs)
I created a very simple plugin to test the usability of a simple
textarea
block for entering just plain text. The relevant JavaScript is as follows:This works fine. I can create a text block, enter the text and it stores it. In my case I'm using a
render_callback
to take thecontent
attribute and manipulate it before displaying it on the front end. So entering this text in the editor works:But entering this type of text breaks things when WordPress tries to load the attributes later:
The problem is if I include any character that has a special meaning in a JSON object:
"
,'
,[
,]
,{
,}
Edit: Looks like it's just the double-quotes that are the problem and it appears the breakdown is here.
These characters are not escaped in the object when it's saved to the database, so when the attributes are reloaded (either to edit the post or display on the frontend), reading the object fails and therefore no content is provided (either in the editor or in the frontend).
Expected Behavior
Database
post_content
should look like this:Current Behavior
Instead database content looks like this:
Possible Solution
Properly escape the correct characters when building the object.
The text was updated successfully, but these errors were encountered: