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.
Thank you!
Quoting my WordPress/wordpress-develop#5468 (comment):
[...] strictly speaking, the code isn't 100% equivalent, since
striposis case-insensitive, whereasstr_containsisn't. While block editor-generated code shouldn't contain non-lowercase HTML tags, we'd need to wrap$contentinstrtolower()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. |
dmsnell
left a comment
There was a problem hiding this comment.
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
striposwithstr_contains, as per feedback from @spacedmonkey here: WordPress/wordpress-develop#5468.Follow-up to #55269.