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

Saving a block with backslash in RichText wipes out all RichText data within the block #16508

Open
Alexius08 opened this issue Jul 10, 2019 · 7 comments
Assignees
Labels
[Feature] Block API API that allows to express the block paradigm. [Package] Rich text /packages/rich-text [Type] Bug An existing feature does not function as intended

Comments

@Alexius08
Copy link

Describe the bug
Inputting backslashes into RichText components inside a PHP-rendered block results into loss of saved data inside all RichText components within the affected block.

To reproduce
Steps to reproduce the behavior:

  1. Make a minimum variable block with at least two RichText input components and render it using PHP.
  2. Use the block on a post, set the value of the RichText components to normal strings and save it.
  3. Refresh the post editor for the post with the block and replace the contents of one of the RichText components with at least one backslash.
  4. Preview to see the value of RichText-dependent attributes within the block reduced into empty strings. Save to overwrite all values with empty strings.

Expected behavior
Normal behavior is preserving all values of RichText-dependent attributes even when the backspace-filled string is inputted.

Screenshots
PHP-rendered block with two RichText inputs filled with normal values, as seen in the editor.
PHP-rendering bug p1

PHP-rendered block with two RichText inputs filled with normal values, as seen in the preview.
PHP-rendering bug p2

PHP-rendered block with two RichText inputs, one of them filled with only backslashes, as seen in the editor.
PHP-rendering bug p3

PHP-rendered block with two RichText inputs, one of them filled with only backslashes, as rendered in the preview. Saving the post at this state leads to removal of all data in the RichText inputs.
PHP-rendering bug p4

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser: Chrome
  • Version: Wordpress 5.2.2, PHP 7.2.9
@swissspidy swissspidy added [Package] Rich text /packages/rich-text Needs Testing Needs further testing to be confirmed. labels Jul 10, 2019
@talldan talldan added [Type] Bug An existing feature does not function as intended and removed Needs Testing Needs further testing to be confirmed. labels Dec 12, 2019
@ehti
Copy link

ehti commented Dec 12, 2019

Able to reproduce this! Thanks for the report @Alexius08

For easier testing, we can also use the Search block instead of creating a new block. Title in the search block is RichText and rendered in PHP.

  1. Add search block to a post
  2. Change the title from Search to ABC\. Save draft
  3. Refresh the page
  4. Title will be gone and it gets reset to just Search

(Backslashes are a problem).

Also ref https://wordpress.slack.com/archives/C02QB2JS7/p1576127699440400

@skorasaurus
Copy link
Member

Hi,

I'm still able to reproduce this as of Gutenberg 13.2.; note that this only occurs if the last character in the saved attributed is a backslash;

for example, in the test case above by @ehti ; if you change the title in title block to "search for records and\or data" ; the attribute will be saved ;but if you finish it as ABC\ it will not.

@dmsnell
Copy link
Member

dmsnell commented Jun 12, 2023

@Mamaduka @youknowriad to be clear and get it out of the way, this isn't related to the recent type: 'raw' change is it?

@youknowriad
Copy link
Contributor

@dmsnell I don't think so as that change is only applied to some blocks not all RichText blocks and this bug is about a custom block with two rich text elements.

@dmsnell
Copy link
Member

dmsnell commented Jun 12, 2023

thanks @youknowriad - I can imagine some plausible ways this could go wrong.

Can we get a copy of before/after post_content/HTML for these posts when the error is present?

@Mamaduka
Copy link
Member

Mamaduka commented Jun 12, 2023

The search button text has a type: 'string'. This is what block HTML output looks like when I add a backslash at the end of the string.

Edit: I can only reproduce the issue when the string attribute is serialized in the block comment.

<!-- wp:search {"label":"Search","buttonText":"Search \\u0022} /-->

Screenshot

CleanShot 2023-06-12 at 21 14 44

@Mamaduka
Copy link
Member

I believe this regression was introduced in #6619.

@Mamaduka Mamaduka added the [Feature] Block API API that allows to express the block paradigm. label Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Block API API that allows to express the block paradigm. [Package] Rich text /packages/rich-text [Type] Bug An existing feature does not function as intended
Projects
None yet
Development

No branches or pull requests

8 participants