-
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
Footnotes: checking type before using count() #53660
Conversation
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 couldn't reproduce the error in PHP 7.4 or PHP 8.0, but decided it wouldn't hurt to first check if $footnotes was an array before we attempt to pass it through count().
I couldn't reproduce the issue with PHP 7.4 or PHP 8, either. I wonder what shape $footnotes
was in that resulted in it being null
in the reported issue? I guess somehow the result from get_post_meta
would need to be truthy, but when passed through json_decode
, it winds up being null
? The PHP docs mention that null
is returned if the JSON cannot be decoded, so I wonder if there's a condition somewhere that can happen where the post meta value for Footnotes is not valid JSON 🤔
In any case, the ! is_array()
check looks like a good way to guard against this error for now 👍
Yeah, I feel like we're puttying over what could be a real bug. I also tried with special characters but no dice. |
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 can't reproduce the issue either, but this change it doesn't seem to break anything.
Yeah, totally. Still, this PR shouldn't hurt, and ideally if for some reason the Footnotes meta isn't valid JSON, I think silently returning nothing at render time is probably the best bet rather than throwing errors. |
Okay, I can reproduce I think. It seems to only happen on autosave. The footnotes are not being escaped. So we add a few Here's what [{
"content": "sdasdfas!!@#$%^&*()": ; ? > & lt;,
. / {}
"''/']{></{}dfasdf",
"id" : "b06691e4-f584-4c51-9a4b-a49c87a6abb8"
}, {
"content": ""
sdfsdf 'd '
a "",
"id": "cc13626b-a993-49e7-a092-9581ecbdb0b0"
}, {
"content": "adsfdsfasdf",
"id": "5b4d0fe6-f2bb-4051-b398-f671a908e995"
}] |
Great catch, that's consistent for me, too, and only on auto-save. |
Closing this as it doesn't address the core issue. This PR does 🤞🏻 |
This is probably still valuable. |
Yes, let's definitely prevent |
Okay! I'll restore 😄 Thanks, folks |
* Footnotes: Fix recursion into updating attributes when attributes is not an object (#53257) * Fix crash by moving editor style logic into a hook with useMemo (#53596) * Move editor style logic into a hook whith useMemo * Remove unnecessary useMemo * Move the whole logic inside the 'useMemo' * Add missing useSelect dep --------- Co-authored-by: George Mamadashvili <georgemamadashvili@gmail.com> * Adding an is_array check before using count in case $footnotes is not countable (#53660) * Footnotes: fix accidental override (#53663) * Footnotes: fix accidental override * Remove double quotes * Footnotes: autosave is not slashing JSON (#53664) * Footnotes: autosave saves decoded JSON * wp_slash * Curly quote * Slash on save and restore * Ensure the preview dropdown popover closes (<16.3) for e2e tests --------- Co-authored-by: Andrew Serong <14988353+andrewserong@users.noreply.github.com> Co-authored-by: Noah Allen <noahtallen@gmail.com> Co-authored-by: George Mamadashvili <georgemamadashvili@gmail.com> Co-authored-by: Ramon <ramonjd@users.noreply.github.com> Co-authored-by: Ella <4710635+ellatrix@users.noreply.github.com> Co-authored-by: ramon <ramonjd@gmail.com>
What?
The PR attempts to guard against uncountable values in the footnotes block.
Reported in https://core.trac.wordpress.org/ticket/59103
Why?
I couldn't reproduce the error in PHP 7.4 or PHP 8.0, but decided it wouldn't hurt to first check if
$footnotes
was an array before we attempt to pass it throughcount()
.I tested on WordPress 6.4-alpha and WordPress 6.3.
How?
Adding an
is_array()
check before usingcount()
in case$footnotes
is not countable.Testing Instructions
If you're using
wp-env
, in order to test in PHP 8.0 add the following to.wp-env.json
.And run
npm run wp-env start --update
Ensure that still footnotes work in posts/pages and in the site editor.
As you work, check the logs for warnings using
npm run wp-env logs --watch
.