Skip to content

Bug: Can't escape / (forward slash) in no-restricted-syntax rule. #16555

Open
@RoyRao2333

Description

@RoyRao2333

Environment

Node version: 16.16.0
pnpm version: 7.15.0
Local ESLint version: 8.23.0
Operating System: macOS 13.0.1, M1 Pro

What parser are you using?

@typescript-eslint/parser

What did you do?

Forward slashes are not escaped in no-restricted-syntax.
Regex as below:

const extMatchingRex = /^(?:[\S\t]*[-.& ,+!@#$%\^*\(\);\/\|\<\>"\'?=:_\[\]\{\}~`\t])?(jpg|jpeg|png|gif|svg|webp|apng|pdf|doc|docx|ppt|pptx|xls|xlsx|txt|rtf|md|html|xml|zip|rar|7z|iso|exe|rmvb|avi|mpeg|mp4|m4v|mov|asf|flv|f4v|3gp|mp3|wma|wav|ape|flac|ogg|aac|m4a)(?:[-.& ,+!@#$%\^*\(\);\/\|\<\>"\'?=:_\[\]\{\}~`\t][\S\t]*)?$/

Usage as below:

{
    selector: `Literal[value=${extMatchingRex}]`,
    message: 'Use it uppercased.',
},

No luck putting my regex in a string or RegExp either.

What did you expect to happen?

It should match the following strings:

const jpg = 'jpg';
const jpeg = '.jpeg';
const mixed_png = 'This is a hh .png. hh file';

What actually happened?

image

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

As you can see, my forward slashed is well escaped, but it came up with the error above.
After I removed \/, it went well... How to fix this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    acceptedThere is consensus among the team that this change meets the criteria for inclusionblockedThis change can't be completed until another issue is resolvedbugESLint is working incorrectlycoreRelates to ESLint's core APIs and features

    Type

    No type

    Projects

    Status

    Blocked

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy