Skip to content

add regex testing for non-alpha characters - #4500

Open
baha-bouali wants to merge 1 commit into
mozilla:mainfrom
baha-bouali:fix-regex-non-alpha-match
Open

add regex testing for non-alpha characters#4500
baha-bouali wants to merge 1 commit into
mozilla:mainfrom
baha-bouali:fix-regex-non-alpha-match

Conversation

@baha-bouali

Copy link
Copy Markdown
Contributor

Fixes #4497

[a-zA-z] in the term-matching regex is a typo: the range runs from A (65)
to z (122), so it also covers the six characters that sit between the two
alphabets, which are [, \, ], ^, _ and `. And terms were matched across
them as if they were letters.

example

foo and the source string foo_bar text:

  • before: \bfoo[a-zA-z]*\b matches foo_bar, highlighting the whole
    identifier as the term
  • after: \bfoo[a-zA-Z]*\b does not match. In fact, _ is a word character, so there
    is no word boundary after foo

For the other five characters the old pattern didn't invent a match, it just
made an existing one too long: foo[bar] highlighted foo[bar instead of
foo.

The old suffix matching on actual letters is the same, so add-on still highlights
Add-Ons.

Tests

Added regression coverage for all non-alpha characters in Highlight.test.jsx,
I split them into two because the two groups behave differently:
_ is word character no mark at all, while the five non-word characters yield
exactly one mark equal to the term. Both cases fail against the old pattern.

make test-translate ran successfully after changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect regex in Highlight.tsx

1 participant