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

globstar not working properly #2

Closed
magalhas opened this Issue Jul 22, 2014 · 4 comments

Comments

Projects
None yet
2 participants
@magalhas
Copy link

magalhas commented Jul 22, 2014

I've tried to use your globstar feature and found out that it was very buggy. For instance **/*.js would only return *.js inside any subfolders where it also should match js files at the parent folder.

Do you want me to make a PR with the fix?

@michaldudek

This comment has been minimized.

Copy link
Owner

michaldudek commented Jul 22, 2014

**/*.js correctly should not return files at the root folder.

Bash manual states:

When the globstar shell option is enabled, and ‘’ is used in a filename expansion context, two adjacent ‘’s used as a single pattern will match all files and zero or more directories and subdirectories. If followed by a ‘/’, two adjacent ‘*’s will match only directories and subdirectories.

Also read here:
http://unix.stackexchange.com/questions/117826/bash-globstar-matching

If you want to match *.js at the root folder as well as all subfolders, you should use glob braces option with this pattern:

\MD\Foundation\Utils\FilesystemUtils::glob('{,**/}*.js', GLOB_BRACE)

The pattern in braces will expand to two patterns:

*.js
**/*.js
@magalhas

This comment has been minimized.

Copy link

magalhas commented Jul 22, 2014

Strangely JavaScript/Node task runners (Gulp and Grunt) don't follow that convention. But they also follow minimatch besides globstar.

@michaldudek

This comment has been minimized.

Copy link
Owner

michaldudek commented Jul 22, 2014

I guess comment in node-glob readme explains it:

While strict compliance with the existing standards is a worthwhile goal, some discrepancies exist between node-glob and other implementations, and are intentional.

I decided to follow bash conventions when developing this function, as they were the only conventions I could find! :) Unfortunately, changing this would mean a BC break and I don't want to do that. Fortunately, you can use the GLOB_BRACE pattern.

@magalhas

This comment has been minimized.

Copy link

magalhas commented Jul 22, 2014

Thanks for digging the node-glob's readme file, unfortunately they don't say anything about the double star crawling behaviour besides that it follows the same principles as bash's implementation.

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