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

Escaping paths with backslashes in dir names #262

Open
thorn0 opened this issue Feb 26, 2020 · 4 comments
Open

Escaping paths with backslashes in dir names #262

thorn0 opened this issue Feb 26, 2020 · 4 comments
Assignees

Comments

@thorn0
Copy link

thorn0 commented Feb 26, 2020

Environment

  • OS Version: WSL (10.0.18363.657) Ubuntu 18.04.1 LTS
  • Node.js Version: v10.15.0

Steps to reproduce

  1. Create a dir named a\ and a file in it.
> mkdir 'a\'
> echo 123 > 'a\/test.js'
  1. Try using escapePath to compose a glob to match files inside this dir.

Code sample

fastGlob.sync(fastGlob.escapePath('a\\') + '/*')

Actual behavior

Nothing found.

Expected behavior

The file is found.


escapePath('a\\') returns the same string 'a\\'. The backslash is not understood by fast-glob as a literal character. It needs to be escaped somehow. fastGlob.sync('a\\\\/*') doesn't work, but fastGlob.sync('a@(\\\\)/*') does.

This is further complicated by another bug: escapePath doesn't escape special characters if they're already preceded by a backslash: escapePath('a\\*') === 'a\\*'.

@mrmlnc mrmlnc self-assigned this Mar 2, 2020
@mrmlnc
Copy link
Owner

mrmlnc commented Mar 21, 2020

Thanks for the question!

You are right that multiple escaping will not work.

Right now, I don't see any serious reasons to complicate the escape method, because the current problem looks like an edge case. Looks like some form of an enhancement for the future..

@cincoli
Copy link

cincoli commented Jan 14, 2021

@mrmlnc The problem doesn't only occur in such edge case, but also occurs if the path name includes parenthesis "()[]", etc.
For e.g., I have a directory named: "abc-(123)", it will regard the parenthesis as regular expression grouping mark other than EXACT parenthesis characters... How can I workaround this?

@thorn0
Copy link
Author

thorn0 commented Jan 14, 2021

@liqian5365 This issue is about backslashes. What you wrote doesn't seem to be related. If you believe you encountered a bug, please open another issue with a proper report (steps to reproduce, actual results, expected results).

@mrmlnc mrmlnc added this to the 3.3.0 milestone Jan 1, 2022
@mrmlnc
Copy link
Owner

mrmlnc commented Apr 30, 2023

Actually, there are several problems here:

  1. Here we replace all backslashes with forward slashes. Because of this, we cannot read the entries of the a\\ directory.
  2. The matcher we are using interprets \\ as an escape for /, so it generates regexp ^(?:a\/(?!\.)(?=.)[^/]*?\/?)$ instead of ^(?:a\\\/(?!\.)(?=.)[^/]*?\/?)$. If we add \\\\ to the pattern, the matcher generates the correct regexp, but this leads to problem (1), the a\\\\ directory does not exist.

Mark this issue as a bug. I currently don't have any ideas on how to fix this correctly. I think we should start by fixing the first point.

@mrmlnc mrmlnc removed this from the 3.3.0 milestone Apr 30, 2023
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