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

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

Open
1 task
RoyRao2333 opened this issue Nov 16, 2022 · 5 comments
Open
1 task

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

RoyRao2333 opened this issue Nov 16, 2022 · 5 comments
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion blocked This change can't be completed until another issue is resolved bug ESLint is working incorrectly core Relates to ESLint's core APIs and features
Projects

Comments

@RoyRao2333
Copy link

RoyRao2333 commented Nov 16, 2022

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?

@RoyRao2333 RoyRao2333 added bug ESLint is working incorrectly repro:needed labels Nov 16, 2022
@eslint-github-bot eslint-github-bot bot added this to Needs Triage in Triage Nov 16, 2022
@mdjermanovic mdjermanovic moved this from Needs Triage to Triaging in Triage Nov 16, 2022
@mdjermanovic
Copy link
Member

Hi @RoyRao2333, thanks for the issue!

This seems to be caused by a problem in esquery, explained here:

https://eslint.org/docs/latest/developer-guide/selectors#known-issues

Can you try with \u002F instead of \/ and check if the selector works as expected after the change?

const extMatchingRex = /^(?:[\S\t]*[-.& ,+!@#$%\^*\(\);\u002F\|\<\>"\'?=:_\[\]\{\}~`\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)(?:[-.& ,+!@#$%\^*\(\);\u002F\|\<\>"\'?=:_\[\]\{\}~`\t][\S\t]*)?$/

@RoyRao2333
Copy link
Author

Hi @RoyRao2333, thanks for the issue!

This seems to be caused by a problem in esquery, explained here:

https://eslint.org/docs/latest/developer-guide/selectors#known-issues

Can you try with \u002F instead of \/ and check if the selector works as expected after the change?

const extMatchingRex = /^(?:[\S\t]*[-.& ,+!@#$%\^*\(\);\u002F\|\<\>"\'?=:_\[\]\{\}~`\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)(?:[-.& ,+!@#$%\^*\(\);\u002F\|\<\>"\'?=:_\[\]\{\}~`\t][\S\t]*)?$/

Yes! It works like a charm 🎉 Can this be fixed someday later? Thanks for the big help!

@mdjermanovic mdjermanovic moved this from Triaging to Blocked in Triage Nov 16, 2022
@mdjermanovic mdjermanovic added core Relates to ESLint's core APIs and features accepted There is consensus among the team that this change meets the criteria for inclusion blocked This change can't be completed until another issue is resolved and removed repro:needed labels Nov 16, 2022
@mdjermanovic
Copy link
Member

This can only be fixed in esquery. I'll leave this issue open as a reminder for us to update the esquery dependency when estools/esquery#68 is fixed.

@RoyRao2333
Copy link
Author

This can only be fixed in esquery. I'll leave this issue open as a reminder for us to update the esquery dependency when estools/esquery#68 is fixed.

Got it. Thanks for the help! 🎉

@gfyoung
Copy link
Contributor

gfyoung commented Jan 7, 2023

Just curious, do we actually see a path forward to addressing the upstream issue?

The upstream repository has open PRs but hasn't been updated for almost two years.

Perhaps cross-pinging some folks over there is needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion blocked This change can't be completed until another issue is resolved bug ESLint is working incorrectly core Relates to ESLint's core APIs and features
Projects
Status: Blocked
Triage
Blocked
Development

No branches or pull requests

3 participants