forked from WordPress/gutenberg
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parser: Fix JS/PHP inconsistencies with empty attributes (WordPress#1…
…1434) This patch updates a couple of inconsistent behaviors when dealing with empty attributes and with the way PHP and JS treat empty objects differently. ## PHP empty attributes When returning blocks without attributes the spec PHP parser has been sending `[]` instead of `{}` due to complications of how PHP serializes empty arrays to JSON. In this patch we're adding a new test to verify the behavior and then fixing the spec parser so that the output from the PHP version matches the output from the JS version identically. ## Bug with empty attributes in comments The default parser introduced a bug where `<!-- wp:anything {} /-->` would fail to parse because it expected some content inside the curly brackets for the JSOn attributes. This is fixed in this patch by changing the `+?` quantifier in the RegExp tokenizer with a `*?` to allow for empty attributes. A test suite has been added to verify that when we parse an array of different block formulations that they produce what we expect. A bug in a test was the reason I didn't originally find this bug.
- Loading branch information
Showing
8 changed files
with
136 additions
and
86 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 0 additions & 29 deletions
29
packages/block-serialization-default-parser/test/__snapshots__/index.js.snap
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.