#56980 closed defect (bug) (fixed)
Check that the Normalizer class exists in remove_accents()
Reported by: | SergeyBiryukov | Owned by: | SergeyBiryukov |
---|---|---|---|
Milestone: | 6.1.1 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Formatting | Keywords: | has-patch commit |
Focuses: | Cc: |
Description
Background: #24661, #30130, #35951, #47763, #52654.
After the 6.1 release, seeing a few errors like this on support forums and Google search results:
Uncaught Error: Class 'Normalizer' not found in .../wp-includes/formatting.php:1605
Introduced in [53754]. There is a function_exists( 'normalizer_normalize' )
check, but apparently some plugins polyfill that function while the Normalizer
class is still not available, see comment:22:ticket:35951. This can happen when the intl
PHP extension is not loaded.
I believe we should add a class_exists( 'Normalizer' )
check here.
Attachments (4)
Change History (27)
This ticket was mentioned in Slack in #forums by zodiac1978. View the logs.
2 years ago
This ticket was mentioned in Slack in #forums by clorith. View the logs.
2 years ago
#4
@
2 years ago
It appears that the plugin polyfills the
normalizer_normalize()
function, but theNormalizer
class has a different namespace there,p\Normalizer
, soNormalizer::FORM_C
produces a fatal error.
Is there a case where Core should allow for the polyfill's version to be used?
#5
in reply to:
↑ 1
@
2 years ago
Replying to mukesh27:
We need both class to be exist? or any one?
Both the normalizer_normalize()
function and the Normalizer::FORM_C
constant are used in the affected code, so I think we should check if both are available.
Replying to hellofromTonya:
Is there a case where Core should allow for the polyfill's version to be used?
Good question! Maybe, but I'm not sure it's possible.
See the UpdraftPlus plugin for example, which uses the Symfony polyfill for Normalizer, but the Normalizer class has a different namespace there, p\Normalizer
, so Normalizer::FORM_C
produces a fatal error.
How do we get the correct Normalizer::FORM_C
value in that case? Should we also check for p\Normalizer
?
#6
follow-up:
↓ 8
@
2 years ago
On a closer look, it appears that Normalizer::FORM_C
is the default value both for normalizer_is_normalized() and normalizer_normalize(), so perhaps we can just remove it. That way the polyfilled function should work.
This ticket was mentioned in Slack in #forums by zoonini. View the logs.
2 years ago
#8
in reply to:
↑ 6
;
follow-up:
↓ 11
@
2 years ago
Replying to SergeyBiryukov:
On a closer look, it appears that
Normalizer::FORM_C
is the default value both for normalizer_is_normalized() and normalizer_normalize(), so perhaps we can just remove it. That way the polyfilled function should work.
That's a good point! Core doesn't need to pass the default $form
value since both functions include the default in their function parameters. Then if the intl
package is not available, the polyfill handles it.
56980.2.diff should work.
@SergeyBiryukov how can this be tested?
This ticket was mentioned in Slack in #forums by zoonini. View the logs.
2 years ago
This ticket was mentioned in Slack in #forums by yui. View the logs.
2 years ago
#11
in reply to:
↑ 8
@
2 years ago
Replying to hellofromTonya:
@SergeyBiryukov how can this be tested?
I think we need to have a PHP compiled without the --enable-intl
option, otherwise I'm afraid there is no way to disable this extension via php.ini.
Plugins with the polyfill are found here:
https://wpdirectory.net/search/01GGYGZXMMWWG4FDD3781EKW0W
remove_accents
is for example used if you create a new user, like described here:
https://github.com/woocommerce/woocommerce/issues/35471#issuecomment-1301815362
Non-NFC content can be found in #30130 (PDF attachment).
So this could be a way to test.
#12
@
2 years ago
I'm also experiencing this on some of my client's websites, but as of right now it's only on sites using WooCommerce.
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
2 years ago
#14
follow-up:
↓ 17
@
2 years ago
- Keywords dev-feedback added
@SergeyBiryukov The patch looks good to me generally, seems to assume that normalizer_is_normalized()
exists if normaliser_normalize()
exists. The example polyfills check both, so we might consider this too.
#15
follow-up:
↓ 16
@
2 years ago
So is the "solution" here for WordPress instances running on Ubuntu Server, or say VPS's using OpenLiteSpeed WordPress installs to run these in order?
sudo apt-get update sudo apt install php-intl sudo reboot
Then we can go ahead and update all plugins & update to WordPress 6.1?
#16
in reply to:
↑ 15
@
2 years ago
Replying to jchambo:
So is the "solution" here for WordPress instances running on Ubuntu Server, or say VPS's using OpenLiteSpeed WordPress installs to run these in order?
Yes, this should solve the problem, as then the intl
extension is providing the function directly and no polyfill is necessary. Especially, the namespace problem (and therefore the fatal error) is gone then.
See also:
https://make.wordpress.org/hosting/2021/05/20/why-hosters-should-install-the-php-intl-extension/
#17
in reply to:
↑ 14
;
follow-up:
↓ 20
@
2 years ago
- Keywords changes-requested added; dev-feedback removed
Replying to costdev:
@SergeyBiryukov The patch looks good to me generally, though it seems to assume that
normalizer_is_normalized()
exists ifnormalizer_normalize()
exists. The example polyfills check both, so we might consider this too.
This came to mind for me as well. May be worthwhile to play it safe and also check for function_exists( 'normalizer_is_normalized' )
as well.
This ticket was mentioned in Slack in #core by jeffpaul. View the logs.
2 years ago
#19
@
2 years ago
- Keywords changes-requested removed
56980.3.diff adds an additional function_exists()
check for normalizer_is_normalized
.
#20
in reply to:
↑ 17
@
2 years ago
Replying to desrosj:
Replying to costdev:
The patch looks good to me generally, though it seems to assume that
normalizer_is_normalized()
exists ifnormalizer_normalize()
exists. The example polyfills check both, so we might consider this too.
This came to mind for me as well. May be worthwhile to play it safe and also check for
function_exists( 'normalizer_is_normalized' )
as well.
Thanks! Yes, that makes perfect sense to me. 56980.4.diff is a minor modification to check the functions in the same order as they are called.
We need both class to be exist? or any one?