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

On Windows, paths with brackets [ ] in them cause brackets library to error out #699

Closed
naturalethic opened this issue Mar 30, 2018 · 8 comments

Comments

@naturalethic
Copy link

Watching a path of [routes]/[page].html causes:

snapdragon\lib\parser.js:473
        throw new Error('no parsers registered for: "' + self.input.slice(0, 5) + '"');
        ^

Error: no parsers registered for: "]"

This does not occur in chokidar@1.7

sveltejs/sapper#212

@naturalethic
Copy link
Author

micromatch/braces#16

@naturalethic
Copy link
Author

If chokidar is creating the glob pattern, then that is a bug in chokidar, since glob patterns should only use backslashes for escaping a value. Given that \ in a string is converted to \ in a regex, it is actually escaping [, not the backslash.

@naturalethic naturalethic changed the title On Windows, paths with brackets [ ] in them cause snapdragon to error out On Windows, paths with brackets [ ] in them cause brackets library to error out Apr 2, 2018
@es128
Copy link
Collaborator

es128 commented Apr 3, 2018

If the file paths actually have brackets in them and you're not otherwise trying to use glob patterns then you can use disableGlobbing: true.

@naturalethic
Copy link
Author

@es128 that does fix it... I'm curious though, because watching ../**/* still works, is that not considered globbing?

@es128
Copy link
Collaborator

es128 commented Apr 3, 2018

Yes, it is, but you don't need that. Just watch the directory and chokidar will recursively traverse through everything within it for you.

If you do want to use glob patterns that are more specific you need to make sure you only use forward slashes as path separators and you would need to provide your own escaping of the special glob-relevant characters that are part of the actual file path like \\[routes\\]/\\[page\\].html

@sorentycho
Copy link

sorentycho commented Nov 9, 2018

This isn't a problem with input to the library--filenames (that is, the names of files existing on the filesystem chokidar is being instructed to watch) with square brackets in them cause the issue, not offending glob patterns. In particular, filenames matching the regex .*\\\[.*\] (that is, ones where a pair of square braces immediately follows a path-separating backslash), and the exception is happening inside the braces library, which means that chokidar is running filenames it finds on the filesystem through brace expansion as if they were glob strings. That might be by design but it sounds bug-ish to me.

@jonschlinkert
Copy link

that is, ones where a pair of square braces immediately follows a path-separating backslash

That looks like an invalid glob pattern. Glob patterns may only have forward slashes as path separators. See https://github.com/micromatch/micromatch#backslashes.

Also, fwiw unless you are only tring to match dotfiles inside and outside the brackets, the . should be removed.

@sorentycho
Copy link

It is an invalid glob pattern, yes, because it is the name of a file on the filesystem created by someone else over which I have no control. The glob pattern I'm supplying to chokidar is this: C:/Users/REDACTED/conversations/**/_journal.yml (yes, with forward slashes only, to avoid backslashes being interpreted as escape sequences). The pattern I gave was my attempt at a regex (not glob pattern) describing what filenames are problematic.

To put this another way: If, on on my hard drive, there exists a file with a path like C:\Users\REDACTED\conversations\[breakthings]\_journal.yml, this error occurs, even though I've told chokidar to watch the glob C:/Users/REDACTED/conversations/**/_journal.yml. I never pass any brackets or other globs to chokidar from code. If I remove that file from my hard drive and make no code changes, the exception goes away.

Looking into chokidar's code, it seems that file names obtained from the file system must be getting passed through the getDirParts function--that's where the error is occurring for me.

paulloz added a commit to paulloz/inky that referenced this issue Sep 3, 2019
see paulmillr/chokidar#699 for more info.
ended up disabling the globbings because we're not really using them.
paulloz added a commit to paulloz/inky that referenced this issue Sep 3, 2019
see paulmillr/chokidar#699 for more info.
ended up disabling the globbings because we're not really using them.
paulloz added a commit to paulloz/inky that referenced this issue Sep 3, 2019
see paulmillr/chokidar#699 for more info.
ended up disabling the globbings because we're not really using them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants