Create Sub-strings getting linked

Created on 14 August 2025, about 10 hours ago

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.

🐛 Bug report
Status

Active

Component

User account

Created by

🇺🇸United States khasim_shaik Michigan

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024