- Issue created by @khasim_shaik
- 🇮🇹Italy apaderno Brescia, 🇮🇹
Welcome to drupal.org!
This issue queue is not for reporting issues found on contributed Drupal modules or Drupal core; bugs found in a modules/themes must be reported in their issue queue.
Kudos and patch credit go to Srdjan Popovic → who had the regular expression brains to figure this one out!
Word Link seems to be picking out sub-strings inside other words. For example, it is linking the “hip” in “relationship.”
If you check the “Word Boundary” option in the text format configuration, even the substrings will be converted, but if you leave it unchecked it should respect word boundaries. This is by design, obviously and should in theory be fine.
However, this unchecked option had a bug. It affected only the ending of the word. For example, “relationship” was giving a false positive for “hip”, but “hipo” was not.
Here is the solution on line 342, instead of
$pattern = '/((\b)|(?<=))(' . implode('|', $pattern) . ')\b/ui';
if should be
$pattern = '/\b(' . implode('|', $pattern) . ')\b/ui';
In general (?<=…) matches if the current position in the string is preceded by a match for … that ends at the current position. This is called a "positive lookbehind assertion". (Thankfully learned that from Python as it is not in PHP regex docs!)
In this case it was basically asserting if there is a word boundary OR if the string is preceded by nothing at all (not even an empty space), which is in fact always true. This new approach even covers the situation when the string is at the beginning of the text, but this handles that as well.
Attached is the git patch, which is a one-liner of course.
Active
User account
Welcome to drupal.org!
This issue queue is not for reporting issues found on contributed Drupal modules or Drupal core; bugs found in a modules/themes must be reported in their issue queue.