diff -u b/core/modules/search/search.module b/core/modules/search/search.module --- b/core/modules/search/search.module +++ b/core/modules/search/search.module @@ -865,7 +865,7 @@ while ($max_end_index > $min_end_index) { // Check the index half way between min and max. See if we ended there, // if we would still have a match. - $proposed_end_index = floor(($max_end_index + $min_end_index) * 0.5); + $proposed_end_index = floor(($max_end_index + $min_end_index) / 2); $proposed_end_pos = $words[$proposed_end_index][1]; // Since the split was done with preg_split(), the positions are byte counts // not character counts, so use substr() not Unicode::substr() here. @@ -875,8 +875,8 @@ $max_end_index = $proposed_end_index; } else { - // The proposed endpoint is too early, so the earliest possible - // OK ending would be the next word. + // The proposed endpoint index is too early, so the earliest possible + // OK ending point would be the next index. $min_end_index = $proposed_end_index + 1; } } @@ -891,7 +891,7 @@ while ($max_start_index > $min_start_index) { // Check the index half way between min and max. See if we started there, // if we would still have a match. - $proposed_start_index = ceil(($max_start_index + $min_start_index) * 0.5); + $proposed_start_index = ceil(($max_start_index + $min_start_index) / 2); $proposed_start_pos = $words[$proposed_start_index][1]; // Since the split was done with preg_split(), the positions are byte counts // not character counts, so use substr() not Unicode::substr() here. @@ -901,14 +901,17 @@ $min_start_index = $proposed_start_index; } else { - // The proposed start point is too late, so the latest possible - // OK starting point would be the previous word. + // The proposed start point index is too late, so the latest possible + // OK starting point would be the previous index. $max_start_index = $proposed_start_index - 1; } } $start_index = $max_start_index; - // Return the matching text. + // Return the matching text. We need to use substr() here and not the + // Unicode::substr() function, because the indices in $words came from + // preg_split(), so they are Unicode-safe byte positions, not character + // positions. return trim(substr($text, $words[$start_index][1], $words[$end_index][1] - $words[$start_index][1])); }