Via T274903: Change template search in VisualEditor to use standard search API (patch https://gerrit.wikimedia.org/r/689070) we made the search add a * at the end of the user's input to be able to find incomplete prefixes. Turns out this is problematic in several situations:
- foo * behaves the same as foo. The star is just pointless.
- "foo"* searches for the literal "asterisk".
- foo_* and foo** don't find anything.
- foo:* might be actual CirrusSearch syntax in case the word is a known keyword.
- All other special characters I tried are ignored. It appears like it behaves as if the star was not added. I.e. foo!* and foo! behave the same.
Proposed solutions (from less to more strict):
- Exclude the problematic characters: if ( !/[\s"*:_]$/.test( … ) )
- Exclude entire classes of special characters: if ( !/[\p{P}\p{S}\p{Z}]$/u.test( … ) )
- Add the star only after word characters: if ( /[\p{L}\p{N}]$/u.test( … ) ) (Note: Don't use \w because it does not include Umlauts and such.)
I actually suggest to go with #3. It's the only one that adds the star only if we are sure it is useful, which is how it should be. All other proposals require us to know all edge-cases, which typically turns out to be impossible.
This applies to VisualEditor and MediaWiki-extensions-TemplateWizard. No need for 2 tickets. The code will probably be exactly the same.