Skip to content

regular expression: incorrect detection of unnecessary escaped characters in character class #5487

@Boshen

Description

@Boshen

Discovered in monitor-oxc: https://github.com/oxc-project/monitor-oxc/actions/runs/10720462114/job/29726880245

Input:

/([\da-z][\d\-a-z]{0,31}):((?:[\w!$'()*+,\-.:;=@]|%[\da-f]{2})+)/iu;

Expected:

esbuild: https://esbuild.github.io/try/#dAAwLjIzLjEALS10YXJnZXQ9ZXMyMDE1AGNvbnN0IFVSTl9SRUcgPSAvKFtcZGEtel1bXGRcLWEtel17MCwzMX0pOigoPzpbXHchJCcoKSorLFwtLjo7PUBdfCVbXGRhLWZdezJ9KSspL2l1Owo

/([\da-z][\d\-a-z]{0,31}):((?:[\w!$'()*+,\-.:;=@]|%[\da-f]{2})+)/iu;

Oxc Output:

new RegExp("([\\da-z][\\d-a-z]{0,31}):((?:[\\w!$'()*+,-.:;=@]|%[\\da-f]{2})+)", "iu")

This is a really weird one ...

/([\da-z][\d\-a-z]{0,31}):((?:[\w!$'()*+,\-.:;=@]|%[\da-f]{2})+)/iu;
            ^ This backslash

The linter reports unnecessary backslash, but we can't actually remove it, nor need to transform it 😵

Metadata

Metadata

Assignees

Labels

C-bugCategory - BugP-highPriority - High

Type

No type

Priority

None yet

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions