* Escape dot in token since it will be used in a regex (for good
measure)
* Add `(?![\w-])` to ensure that `td` is not followed by other
characters that would make it a different element.
* Instead of the first `.+?`, use `((?!</td>).)*` which matches zero or
more characters but refuses to consume if it encounters `</td>`
* Escape curly braces (for good measure)
* Instead of the second `.+?`, use `.*?` so that it will match if there
are zero characters. (Note: this change is really the crux of the
issue, as described in CRM-21264).
* Complete then closing `</td>` (for good measure)
* @return bool
*/
public static function isHtmlTokenInTableCell($token, $entity, $textToSearch) {
- $tokenToMatch = $entity . '.' . $token;
- $pattern = '|<td.+?{' . $tokenToMatch . '}.+?</td|si';
+ $tokenToMatch = $entity . '\.' . $token;
+ $pattern = '|<td(?![\w-])((?!</td>).)*\{' . $tokenToMatch . '\}.*?</td>|si';
$within = preg_match_all($pattern, $textToSearch);
$total = preg_match_all("|{" . $tokenToMatch . "}|", $textToSearch);
return ($within == $total);