-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Parser: Fix JS/PHP inconsistencies with empty attributes #11434
Conversation
7ccba0b
to
7613e65
Compare
Since the introduction of the default parsers we have had a bug in the PHP version whereby inner blocks were being popped onto the output stack as PHP classes instead of as simple associated arrays. Blocks that weren't inner blocks were being properly type-casted as arrays. This patch adds the cast in where it's needed in order to fix this inconsistent behavior. So far this hasn't caused any troubles or exposed itself but while working on other PRs like #11434 it became evident in test code.
I was about to approve this, but in the course of testing I found an issue that is also present in Open Gutenberg's Code Editor, paste the following:
I expected this to be preserved verbatim or at the very least to have the middle block "self-correct" by deleting its empty attributes object. Instead, upon blurring the code editor, I get this:
Comparing the two spec and default parsers: I assume this to be independent of the current PR, so it's up to you whether we should address it separately. In any case, 👍. |
^ to be clear, I'm not concerned about the parser discrepancies when it comes to collecting empty freeform nodes — just the missing |
84a57db
to
e71c1ee
Compare
Squashed and rebased; former HEAD was 052c689 |
@mcsf I folded the |
With d1acdf6 @mcsf are we good to 🚢 ? |
Since the introduction of the default parsers we have had a bug in the PHP version whereby inner blocks were being popped onto the output stack as PHP classes instead of as simple associated arrays. Blocks that weren't inner blocks were being properly type-casted as arrays. This patch adds the cast in where it's needed in order to fix this inconsistent behavior. So far this hasn't caused any troubles or exposed itself but while working on other PRs like #11434 it became evident in test code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍🏻 Looks good!
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 serializesempty 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 {} /-->
wouldfail 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 RegExptokenizer 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.