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

Globby skips folder with symbols in it's name #81

Open
UltraDosaaf opened this issue Apr 5, 2018 · 14 comments
Open

Globby skips folder with symbols in it's name #81

UltraDosaaf opened this issue Apr 5, 2018 · 14 comments

Comments

@UltraDosaaf
Copy link

Can't make globby to search file inside this folder: C:\Users\me\Desktop\github.com + Globby.
I've tryed noext and other options, but without result.

@mrmlnc
Copy link
Contributor

mrmlnc commented Apr 9, 2018

Sorry, @jonschlinkert, but you can take a look at this issue? You have a more experience here :)

const mm = require('micromatch');

const mm0 = mm.makeRe('fixtures/github.com + Globby/**/*');

// /^(?:(?:\.[\\\/](?=.))?fixtures[\\\/]github\.com + Globby[\\\/]?\b(?!\.)(?:(?!(?:[\\\/]|^)\.).)*?[\\\/](?!\.)(?=.)[^\\\/]*?(?:[\\\/]|$))$/

const mm1 = mm.makeRe('fixtures/github.com + Globby/**/*', { noext: true});

// /^(?:(?:\.[\\\/](?=.))?fixtures[\\\/]github\.com + Globby[\\\/]?\b(?!\.)(?:(?!(?:[\\\/]|^)\.).)*?[\\\/](?!\.)(?=.)[^\\\/]*?(?:[\\\/]|$))$/

const mm2 = mm.makeRe('fixtures/github.com + Globby/**/*', { noext: false});

// /^(?:(?:\.[\\\/](?=.))?fixtures[\\\/]github\.com + Globby[\\\/]?\b(?!\.)(?:(?!(?:[\\\/]|^)\.).)*?[\\\/](?!\.)(?=.)[^\\\/]*?(?:[\\\/]|$))$/

I think that we lost \ before + where noext option is enabled.

@garyking
Copy link
Contributor

garyking commented Aug 3, 2018

I can confirm that globby won't return any results if passed a dir with characters like square/round brackets in its name. Anyone got a fix for that?

Edit: Looks like the noext: true option fixed it for me.

@sindresorhus
Copy link
Owner

Would you be able to submit a pull request with one or more failing tests? That would help getting this fixed faster.

@vladimiry
Copy link

There is also issue with "+" character, see details here renke/import-sort#71.

@idevelop
Copy link

idevelop commented Jan 13, 2019

Hey folks, having come across this issue while investigating the issue linked above in the Google datastore library, my take is that this isn't something that globby should fix, since it by design accepts patterns like +(a|b), and it should be the developer's responsibility to properly escape any special characters in the path that are unintentional wildcards / patterns.

@sindresorhus do you have any suggestions for how a developer should write a sanitization function that correctly escapes all characters, like +()[]{} etc?

@sindresorhus
Copy link
Owner

do you have any suggestions for how a developer should write a sanitization function that correctly escapes all characters, like +()[]{} etc?

I agree that would be useful. Can you open a feature request on https://github.com/mrmlnc/fast-glob? It needs to be implemented there first. Something like fastGlob.escapeGlob().

@idevelop
Copy link

@sindresorhus done: mrmlnc/fast-glob#158

@martpie
Copy link

martpie commented Mar 3, 2019

The package glob-escape helps developers escaping strings with folder names including characters like [ ] ( ), but globby still returns an empty array when running something like:

const test = await globby('/some/directory/test \(with escaped parenses\)/**/*')
➜  museeks git:(master) ✗ ls -la ~/Google\ Drive/Music/Air\ \(test\)/Moon\ Safari
total 123248
drwxr-xr-x  12 pierre  staff       384 Dec 16  2017 .
drwxr-xr-x   9 pierre  staff       288 Mar  3 12:54 ..
-rw-------   1 pierre  staff  10355029 Jan 12  2014 01 La Femme D'Argent.mp3
-rw-------   1 pierre  staff   7167036 Jan 12  2014 02 Sexy Boy.mp3
-rw-------   1 pierre  staff   6443550 Jan 12  2014 03 All I Need.mp3
-rw-------   1 pierre  staff   5414128 Jan 12  2014 04 Kelly Watch The Stars.mp3
-rw-------   1 pierre  staff   6165188 Jan 12  2014 05 Talisman.mp3
-rw-------   1 pierre  staff   3706946 Jan 12  2014 06 Remember.mp3
-rw-------   1 pierre  staff   5800944 Jan 12  2014 07 You Make It Easy.mp3
-rw-------   1 pierre  staff   5261128 Jan 12  2014 08 Ce Matin La.mp3
-rw-------   1 pierre  staff   8178320 Jan 12  2014 09 New Star In The Sky (Chanson Pour Solal).mp3
-rw-------   1 pierre  staff   4584689 Jan 12  2014 10 Le Voyage De Penelope.mp3
➜  museeks git:(master) ✗ node
> (async () => { console.log('results', await globby('~/Google\ Drive/Music/Air\ \(test\)/**/*')) })()
> results []

It looks to me like a globby bug no?

edit: After some research, it looks like a micromatch bug:

> mm.isMatch('/some path/tada', '/some path/**/*')
true
> mm.isMatch('/some path[test]/tada', '/some path\[test\]/**/*')
false

@martpie
Copy link

martpie commented Mar 3, 2019

My bad, you have to escape the anti-slash escaping the special caracters as well 🙃

> mm.isMatch('/some path[test]/tada', '/some path\\[test\\]/**/*')
true

Ref: micromatch/micromatch#77 (comment)

But it seems globby is still failing to retrieve the files when specifying the path directly:

> (async () => { console.log('results', await globby('/Users/pierre/Google Drive/Music/Air/**/*')) })()
> results [
  ...
  '/Users/pierre/Google Drive/Music/Air/Talkie Walkie [test]/08 Alpha Beta Gaga.mp3',
  '/Users/pierre/Google Drive/Music/Air/Talkie Walkie [test]/09 Biological.mp3',
  '/Users/pierre/Google Drive/Music/Air/Talkie Walkie [test]/10 Alone In Kyoto.mp3' ]

> (async () => { console.log('results', await globby('/Users/pierre/Google Drive/Music/Air/Talkie Walkie \\[test\\]/**/*')) })()
> results []

@thorn0
Copy link

thorn0 commented Feb 23, 2020

Now that fast-glob has escapePath, it would be good if globby made that function available too.

@nfantone
Copy link

nfantone commented Aug 25, 2020

This seems to have been fixed sometime after opening the issue. I just cloned the repository, installed dependencies and:

> const globby = require('.');
undefined
> (async () => console.log(await globby('/path/src/pages/jobs/[slug].js')))();
Promise { <pending> }
> [
  '/path/src/pages/jobs/[slug].js'
]

Since the project doesn't feature a lock-file is hard to say if an in-range version of some upstream dependency fixed the issue for us or not.

@guiaramos
Copy link

guiaramos commented Nov 27, 2020

I have issue when trying to ignore the following on next.js:

pages/[...error]/index.tsx

and found this pattern:

'!../pages/\\[*\\]/*.tsx'
'!../pages/\\[*\\]/**/*.tsx'

@vnugent
Copy link

vnugent commented Dec 23, 2021

I'm having this issue with parenthesis :

  const currentDir = `West side (Left)` // <--- parenthesis

  const climbFiles = await globby([
    `${currentDir}/*.md`,
    `!${currentDir}/index.md`,
  ]);

 // climbFiles = [] empty array

@Kiyozz
Copy link

Kiyozz commented Aug 5, 2023

Same problem with next.js' parenthesis folders and using xo

Example structure:

src/app/layout.tsx
src/app/(main)/page.tsx

xo --fix src ← (main)/page.tsx is parsed
xo --fix "src/app/(main)/page.tsx" ← is not parsed because the parenthesis being ignored

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