Issue and fix generated with the help of Claude.
Problem/Motivation
The ignore words regex uses \b, so a hyphen counts as a word boundary. With the default ignore list and hyphens set to "Replace by separator", "Nth-of-a-Kind" becomes nth-kind and a document number such as "26-35-A" becomes 26-35. A value that differs from another only by a trailing "-A" then collides with it and one of them gets a "-0" suffix.
Steps to reproduce
- Keep the default ignore words and punctuation settings.
- Set a node pattern of
[node:title]. - Create a node titled "Nth-of-a-Kind". The alias is
/nth-kind.
Proposed resolution
Add an opt-in setting, "Only remove strings that stand alone between spaces" (ignore_words_whitespace_only), off by default. With it off, nothing changes, so aliases on existing sites stay as they are. Changing the default instead would change the alias of any hyphenated title the next time it is saved or bulk-updated.
With the setting on, only whitespace separates words. The regex becomes (?<!\S)(?:a|an|...)(?!\S) instead of wrapping each word in \b, and the ignore words step runs before "Reduce strings to letters and numbers", since that step turns whitespace into the separator. Both mb_eregi_replace() and preg_replace() support the lookarounds.
With the setting on, this also covers #3059837: Ignored characters treat as word boundaries, where a character set to "No action" acts as a boundary: "a.b" stays "a.b".
Remaining tasks
Review the MR.
User interface changes
A checkbox below "Strings to Remove" on the Pathauto settings form.
Data model changes
A new boolean, pathauto.settings:ignore_words_whitespace_only, with schema. pathauto_update_8109() adds it to existing config as FALSE.
Issue fork pathauto-3641597
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
scotwith1tComment #3
scotwith1tEven if this isn't accepted for core, it at least provides an option if anyone runs into the same issue.
Comment #5
scotwith1tComment #6
scotwith1t