wordpress-seo icon indicating copy to clipboard operation
wordpress-seo copied to clipboard

How-to block crashes when content contains %

Open Ruud-Mens opened this issue 4 years ago • 5 comments

  • [X] I've read and understood the contribution guidelines.
  • [X] I've searched for any related issues and avoided creating a duplicate issue.

If you use a % in a how-to block, then the JSON gets invalid. Resulting in console errors and you can't edit the article in WordPress anymore.

Please describe what you expected to happen and why.

Should be able to edit the article

How can we reproduce this behavior?

  1. Create a new article in WordPress
  2. Add a How to block to it
  3. In one of the blocks, write the following content %appdata%
  4. Publish the article. Now you can't edit the article anymore.

Technical info

Relevant errors: Invalid argument supplied for foreach() in D:\Dev\wpdev\wp-content\plugins\wordpress-seo\src\generators\schema\howto.php on line 61

In the editor: TypeError: Cannot read properties of undefined (reading 'map')

  • If relevant, which editor is affected (or editors):
  • [ ] Classic Editor
  • [X] Gutenberg
  • [ ] Classic Editor plugin
  • Which browser is affected (or browsers):
  • [X] Chrome
  • [X] Firefox
  • [X] Safari
  • [ ] Other

Used versions

  • WordPress version: 5.9.3

  • Yoast SEO version: 18.9

  • Relevant plugins in case of a bug:

  • Tested with theme: GeneratePress and Twenty Twenty-Two

Ruud-Mens avatar May 19 '22 09:05 Ruud-Mens

I am afraid the issue wasn't reproducible when following the instructions given in the steps you provided. No errors were shown when using the %appdata% in the Yoast SEO How-To block.

mmikhan avatar May 19 '22 21:05 mmikhan

Sorry, indeed with only %appdata% it seems to work, however, when adding a \ behind the % seems to trigger the bug:

I have just tested it again with the Twenty Twenty-Two theme. %appdata% seems to work indeed (sorry about that), but changing it to the full path triggers the error:

Content of the step – Or press the Windows key + R – Type the path %appdata%\Microsoft\ and press Enter

Ruud-Mens avatar May 20 '22 06:05 Ruud-Mens

The problem is in ending a field with a backslash (\). For some reason this tries to escape the ending quote in the JSON of the schema which breaks the editor (and the HowTo schema on the frontend). It doesn't look like the percent symbol is related to the issue.

Djennez avatar May 20 '22 08:05 Djennez

Okay, so the only option is to remove the \ in this case? For the command, it doesn't matter in this case.

Ruud-Mens avatar Jun 02 '22 10:06 Ruud-Mens

I am able to reproduce the issue and will mark it as a bug so the dev team can look into this further. Thank you for bringing this to our attention.

mmikhan avatar Jun 02 '22 23:06 mmikhan