-
Notifications
You must be signed in to change notification settings - Fork 4.1k
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
Image Block: Replace stripos with str_contains #55302
Conversation
Co-Authored-By: Jonny Harris <spacedmonkey@users.noreply.github.com>
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.
Thank you!
Quoting my WordPress/wordpress-develop#5468 (comment):
[...] strictly speaking, the code isn't 100% equivalent, since
stripos
is case-insensitive, whereasstr_contains
isn't. While block editor-generated code shouldn't contain non-lowercase HTML tags, we'd need to wrap$content
instrtolower()
to be 100% equivalent.
For all practical purposes, we probably don't need case-sensitivity here; might just be interesting to know if there was any scenario that necessitated using stripos
over strpos
when this was first introduced here.
Thanks @ockham! Pinging @artemiomorales @michalczaplinski to double-check this 🙇 |
Advantages of
Some cons:
I advise caution in switching
To sum up:
Also noting, this change is not required for 6.4 RC1. It could happen later without effect. |
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.
thanks for the contribution, and the intention here. I can see where it would be tempting to make this replacement, but since HTML tag names are case insensitive this was chosen to avoid falsely asserting that there are no IMG elements when there might be.
this test is only asking "is it possible that there is an IMG element?" and the only confident answer it can give is "there are definitely no IMG elements in this HTML," except with the change to str_contains()
it cannot answer that question and introduces a defect.
coincidentally, the fear that someone might assume this is a code styling violation and accidentally introduce this very bug was discussed yesterday. I take fault for adding the optimization without measurement, but I plan on performing a proper analysis when I can and then if it proves valuable enough I'll add a more clear warning not to arbitrarily change the code.
Closing this because it introduces a bug without solving any problems, as it was likely a misunderstanding that led to the proposal. |
What?
Small PR to replace
stripos
withstr_contains
, as per feedback from @spacedmonkey here: WordPress/wordpress-develop#5468.Follow-up to #55269.