search_excerpt() incorrectly assumes that search_simplify_excerpt_match() always returns an array, however this is not true: The function returns FALSE when there are no matches.
With PHP 7.4, this will generate a notice, as the code is trying to use as an array a Boolean value.
| Comment | File | Size | Author |
|---|---|---|---|
| #11 | 3084965-11.patch | 535 bytes | mcdruid |
| #11 | interdiff-3084965-2-11.txt | 548 bytes | mcdruid |
Comments
Comment #2
taran2lComment #3
taran2lComment #4
avpadernoComment #5
hardik_patel_12 commented@Taran2L thankyou for patch, patch in comment #2 LGTM.
Comment #6
hardik_patel_12 commentedComment #7
izmeez commentedThank you. Patch in comment #2 addresses php 7.4 notices when using search block:
Comment #8
mcdruid commentedD8's search.module has a
search_excerpt()function but the code has diverged from D7 to the extent that there is nosearch_simplify_excerpt_match(), and therefore this problem wasn't there when PHP 7.4 compatibility was addressed.Looking at that, I think the patch in #2 looks great.
Re-running the tests for that patch, including with PHP 7.4.
Comment #9
mcdruid commentedSame methodology as #3084955-9: Invalid characters passed for attempted conversion, these have been ignored in _color_unpack() to compare PHP 7.4 exceptions before this patch with after:
Again, I'm not sure why the number of Notices from element_children() changes, but that should be addressed by #3084935: element_children() and DrupalRequestSanitizer::stripDangerousValues() should not use integer keys as array
The other difference in results confirms that this patch resolves the problem in
search_excerpt().So I'm happy with this patch, and think it's ready for final review.
Comment #10
fabianx commentedI disagree with the fix here.
a) The syntax
if ($a = b())leads often to errors down the road, so let's please avoid it.b) That is not the same check - before we checked explicitly for the 'where' component - now we only check for $info
c) The more simpler fix is:
or
unless I miss something.
Comment #11
mcdruid commentedI was thinking we could be fairly confident about what would be returned, but I suppose if
search_simplify_excerpt_match()itself was changed, any assumptions we've made here might cause problems (as unlikely as that seems).Here's a patch which just checks
if (isset($info['where']))as suggested. Simple is good :)Comment #12
mcdruid commentedThe simple patch LGTM.
RTBC and ready for the next round of committer reviews.
Comment #13
fabianx commentedLet's get this in, thanks all.
(gave myself credit for the solution)
Comment #15
mcdruid commentedGreat - thanks all!