Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: use u flag for regexes #12249

Merged
merged 1 commit into from
Feb 5, 2022
Merged

chore: use u flag for regexes #12249

merged 1 commit into from
Feb 5, 2022

Conversation

Biki-das
Copy link
Contributor

Usage of the u flag with regular expressions is recommended.

The u flag has two effects:

It enables correct handling of UTF-16 surrogate pairs.
It ensures the correct behavior of regex character ranges.

/^[👍]$/.test("👍") //→ false
/^[👍]$/u.test("👍") //→ true

Make the regular expression throwing syntax errors early as disabling JavaScript specification Annex B[1] extensions.

Because of historical reason, JavaScript regular expressions are tolerant of syntax errors. For example, /\w{1, 2/ is a syntax error, but JavaScript doesn't throw the error. It matches strings such as "a{1, 2" instead. Such a recovering logic is defined in Annex B of Javascript specification.

The u flag disables the recovering logic Annex B of the Javascript specification. As a result, you can find errors early. This is similar to the strict mode.

@codecov-commenter
Copy link

Codecov Report

Merging #12249 (7031c68) into main (4f4be57) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@           Coverage Diff           @@
##             main   #12249   +/-   ##
=======================================
  Coverage   67.52%   67.52%           
=======================================
  Files         328      328           
  Lines       17244    17244           
  Branches     5069     5069           
=======================================
  Hits        11644    11644           
  Misses       5567     5567           
  Partials       33       33           
Impacted Files Coverage Δ
packages/jest-reporters/src/utils.ts 81.25% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 4f4be57...7031c68. Read the comment docs.

Copy link
Member

@SimenB SimenB left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, thanks!

@SimenB SimenB changed the title Fix:Added u flag for regex chore: use u flag for regexes Feb 5, 2022
@SimenB SimenB merged commit f3390fe into jestjs:main Feb 5, 2022
@github-actions
Copy link

github-actions bot commented Mar 8, 2022

This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 8, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants