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

Forward slash is not escaped #30

Open
septagram opened this issue Sep 21, 2020 · 5 comments
Open

Forward slash is not escaped #30

septagram opened this issue Sep 21, 2020 · 5 comments

Comments

@septagram
Copy link

igornovikov1@~/Documents/Code/wtf-test:$ npm i escape-string-regexp
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN wtf-test@1.0.0 No description
npm WARN wtf-test@1.0.0 No repository field.

+ escape-string-regexp@4.0.0
added 1 package from 1 contributor and audited 1 package in 2.12s
found 0 vulnerabilities

igornovikov1@~/Documents/Code/wtf-test:$ node
> const escape = require('escape-string-regexp')
undefined
> escape ('^test/test$')
'\\^test/test\\$'
@papb
Copy link

papb commented Sep 21, 2020

Why should it? Running new RegExp('\\^test/test\\$') works fine.

@septagram
Copy link
Author

septagram commented Sep 24, 2020

I suppose this is reasonable, but I'd appreciate implementing it anyway (as it does no harm AFAIK) or highlighting it in the docs. My case is a little unusual, I'm passing the regexp into the DefinePlugin in order to use the regexp as a require.context argument -- otherwise non-matching files would be compiled anyway. So, I wrongly expected the slashes to be escaped and ended up with an incredibly arcane error a few weeks later.

@sindresorhus
Copy link
Owner

Package description:

Escape RegExp special characters

It would be both surprising and incorrect if we escaped other characters.

@sindresorhus
Copy link
Owner

I guess we could make it clearer in the readme that only the minimal amount of escaping is done.

@septagram
Copy link
Author

Thanks, that would work :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants