-
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
Interactivity API: Fix null and number strings as namespaces runtime error. #61960
Conversation
This pull request has changed or added PHP files. Please confirm whether these changes need to be synced to WordPress Core, and therefore featured in the next release of WordPress. If so, it is recommended to create a new Trac ticket and submit a pull request to the WordPress Core Github repository soon after this pull request is merged. If you're unsure, you can always ask for help in the #core-editor channel in WordPress Slack. Thank you! ❤️ View changed files❔ packages/e2e-tests/plugins/interactive-blocks/namespace/render.php |
Size Change: +80 B (0%) Total Size: 1.74 MB
ℹ️ View Unchanged
|
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.
I checked the server side, it seems to handle this well (decodes to associative array and checks for is_array):
<div data-wp-interactive="null"> | ||
<a data-wp-bind--href="state.url" data-testid="null namespace"></a> | ||
</div> | ||
|
||
<div data-wp-interactive="2"> | ||
<a data-wp-bind--href="state.url" data-testid="number namespace"></a> | ||
</div> |
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.
These would've had similar interesting behavior, all the JSON values:
<div data-wp-interactive="true"></div>
<div data-wp-interactive="false"></div>
<div data-wp-interactive="[]"></div>
<div data-wp-interactive='"my namespace is a quoted string"'></div>
packages/interactivity/src/vdom.ts
Outdated
@@ -100,7 +100,8 @@ export function toVdom( root: Node ): Array< ComponentChild > { | |||
const namespace = regexResult?.[ 1 ] ?? null; | |||
let value: any = regexResult?.[ 2 ] ?? attributeValue; | |||
try { | |||
value = value && JSON.parse( value ); | |||
const parsedValue = JSON.parse( value ); | |||
value = isObject( parsedValue ) ? parsedValue : value; | |||
} catch ( e ) {} |
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.
Nit: we can omit ( e )
when not using the error:
} catch ( e ) {} | |
} catch {} |
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.
Fixed in b7b6da8
c7367ba
to
afb5f80
Compare
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.
To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Flaky tests detected in 4309428. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/9253786308
|
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.
I tested this and it does allow me to make a (terribly named) store with the namespace null
.
|
||
store( 'null', { | ||
state: { | ||
url: '/some-url', |
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.
I'd like to see different values in the different stores. I think it's unlikely, but one could imagine falsy values evaluating to the same store.
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.
Done in 64e275d
TBH, I'm not 100% sure if we should allow this values to be namespaces 😅 |
…error. (WordPress#61960) * Fix null and number strings as namespaces runtime error * Update with suggestions * Update changelog * added wrong css changes * Revert move isObject to utils * Rename url vars Co-authored-by: cbravobernal <[email protected]> Co-authored-by: sirreal <[email protected]>
…error. (WordPress#61960) * Fix null and number strings as namespaces runtime error * Update with suggestions * Update changelog * added wrong css changes * Revert move isObject to utils * Rename url vars Co-authored-by: cbravobernal <[email protected]> Co-authored-by: sirreal <[email protected]>
What?
Right now, creating a namespace called
null
or an integer24
will kill the runtime.Why?
We are doing a JSON.parse() function that returns
null
type ornumber
type if receivesnull
ornumber
strings.How?
By checking if it is an object.
Testing Instructions