Skip to content

bug: brand and competitor names that start or end with a non-ASCII letter or punctuation are never counted as mentions #871

Closed

Description

@gkhngyk

Description

Brand and competitor mentions are counted with a regex built as \b${escaped}\b in server/src/lib/response-parser.js:

  • countOccurrences (line 20): feeds mentionCount and competitor mention counts in countBrandMentions and parseResponse
  • firstOccurrenceIndex (line 92): feeds computeMentionPosition

JavaScript's \b only treats ASCII [A-Za-z0-9_] as word characters (even with the u flag). When a name starts or ends with anything else — an accented letter, a non-Latin script, or punctuation — there is no "word boundary" where one is expected, and the name never matches.

countBrandMentions('I like Émile Studio. Émile Studio is great.', { brandName: 'Émile Studio', domains: [] }); // 0
countBrandMentions('I like Acme!. Acme! is great.', { brandName: 'Acme!', domains: [] });                     // 0
countBrandMentions('I like C++. C++ is great.', { brandName: 'C++', domains: [] });                           // 0
countBrandMentions('I like Acme. Acme is great.', { brandName: 'Acme', domains: [] });                       // 2

For a brand like that, every answer reports zero mentions and no mention position, so visibility looks like zero even when the AI names the brand in every answer. The same applies to competitors.

Expected behavior

A name is matched as a whole word regardless of the script or characters it starts and ends with, and is still not matched inside a longer word (Acme must not match Acmegroup).

Suggested fix

Replace \b in both helpers with Unicode-aware lookarounds and add the u flag, for example:

new RegExp(`(?<![\\p{L}\\p{N}_])${escaped}(?![\\p{L}\\p{N}_])`, 'giu')

Add cases to server/src/lib/response-parser.test.js: accented and non-Latin names, names ending in punctuation (Acme!, C++), a name inside a longer word (no match), and computeMentionPosition ordering with such a name.

Run yarn test from server/ before opening the PR — see CONTRIBUTING.md.

Activity

  1. added
    bug
    good first issue
    help wanted
    ai visibility
    and removed
    good first issue
    help wanted
    on Oct 3, 2026
  2. self-assigned this
    on Oct 3, 2026
  3. added a commit that references this issue on Oct 15, 2026
    d0b88b3
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

ai visibilitybug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions