Skip to content

Don't emit prefer-w when both i and u flags are set #811

@tats-u

Description

@tats-u

Information:

  • ESLint version: 9.21.0
  • eslint-plugin-regexp version: 2.7.0

See https://github.com/fabian-hiller/valibot/blob/main/library/package.json and https://github.com/fabian-hiller/valibot/blob/main/pnpm-lock.yaml

Description

When both i and u flags are set, \w matches U+017F & U+212A, too. This plugin must not emit prefer-w on just [0-9a-z_] under that condition.

eslint/eslint#19474 (comment)

const ex1 = /^[0-9A-Z_]+$/iu;
const ex2 = /^\w+$/iu;

const str = "\u017f\u212a";

// ESLint expected: true / actual: false
console.log(ex1.test(str) === ex2.test(str));

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Regular_expressions/Character_class_escape#w

If the regex is Unicode-aware and the i flag is set, it also matches other Unicode characters that get canonicalized to one of the characters above through case folding.

↑This makes U+017F and U+212A matches \w in iu flag.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions