Fix emoji search to normalize spaces, hyphens, underscores

What does this MR do and why?

Fixes the emoji picker search so that queries using spaces, hyphens, or underscores as word separators all return the same results. For example, searching thank you, thank-you, and thank_you now all match :thank_you:.

Root cause: getNameMatch, getAliasesMatchingQuery, and getDescriptionMatch in app/assets/javascripts/emoji/index.js only stripped underscores from emoji names/aliases when the query itself contained no underscore. Queries containing spaces or hyphens were never normalised, so they never matched underscore-separated emoji names.

Fix: Add a createSeparatorPattern helper that builds a boundary-preserving regex from the query: the query is split on separators (/[\s_-]+/) and the words are re-joined with [\s_-]+, so any separator in the query matches any separator in the candidate field. Because word boundaries are preserved (rather than stripping separators entirely), a query like s mile does not match smile. The pattern is applied symmetrically in all three match functions, and separator-normalised hits receive a +0.5 score penalty so exact/substring matches still rank ahead. The legacy underscore-stripping path is preserved for backward compatibility.

References

Resolves #606540 (closed)

Screenshots or screen recordings

Before After

How to set up and validate locally

Testing with :thank_you: isn't possible in the GDK, try upside down instead:

  1. Open the emoji picker (e.g. on any issue or MR reaction button)
  2. Search for upside down (with a space) — previously returned nothing, now returns :upside_down:
  3. Search for upside-down (with a hyphen) — same result
  4. Search for upside_down (with an underscore) — still works as before
  5. Run Jest tests: node_modules/.bin/jest spec/frontend/emoji/index_spec.js

Note: :thank_you: does not exist in the emoji dataset. Use :upside_down: (or similar multi-word emojis like :heart_eyes:, :cold_sweat:) to validate the fix manually.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Vanessa Otto

Merge request reports

Loading
Loading