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

support empty alternate glob patterns #1368

Open
StaticPH opened this issue Sep 7, 2019 · 2 comments
Open

support empty alternate glob patterns #1368

StaticPH opened this issue Sep 7, 2019 · 2 comments
Labels
enhancement An enhancement to the functionality of the software.

Comments

@StaticPH
Copy link

StaticPH commented Sep 7, 2019

What version of ripgrep are you using?

ripgrep 11.0.2
-SIMD -AVX (compiled)
+SIMD +AVX (runtime)

How did you install ripgrep?

Installed with cargo

What operating system are you using ripgrep on?

Windows 8.1 Pro (x86_64)
If it's relevant, I'm also using the latest version of msys2-x86_64

Describe your question, feature request, or bug.

Bash and ripgrep evaluate globs differently, which seems like a bug to me.
If this behavior is actually intended, I'd like help finding a glob pattern that will give the result bash does for my test pattern.

If this is a bug, what are the steps to reproduce the behavior?

In a directory I have 5 files containing only the string 'qwertyuiop'
The files are named:
'.foo' '.foo_baz' 'bar.foo' 'baz.foo_bar' 'SHOULD_NOT_BE_GLOBBED'

I do not have any .ignore-like files, am not instructing ripgrep to use a configuration file, and have not set RIPGREP_CONFIG_PATH

The glob pattern I am using for this test is {*,}.foo{_*,}
The regex is simply "\D", which should match every character in the 5 files

If this is a bug, what is the actual behavior?

See https://gist.github.com/StaticPH/c52d9ddee8a1a43a23196f5f46f1503e

If this is a bug, what is the expected behavior?

Simply calling echo {*,}.foo{_*,} in bash prints out baz.foo_bar bar.foo .foo_baz .foo, so I would have expected both

~/.cargo/bin/rg -uu --type-add 'foo: {*,}.foo{_*,}' -tfoo "\D"
and
~/.cargo/bin/rg -uu -g '{*,}.foo{_*,}' "\D"

to output

.foo_baz
1:qwertyuiop

.foo
1:qwertyuiop

bar.foo
1:qwertyuiop

baz.foo_bar
1:qwertyuiop

and for

~/.cargo/bin/rg -uu --type-add 'foo:{*,}.foo{_*,}' -Tfoo --debug "\D"

to output

SHOULD_NOT_BE_GLOBBED
1:qwertyuiop
@StaticPH
Copy link
Author

StaticPH commented Sep 7, 2019

Possibly related to globbing behavior mentioned in #1221 ?

@okdana
Copy link
Contributor

okdana commented Sep 7, 2019

That ticket seems only tangentially related. I think your problem here is related to the fact that ripgrep just drops empty alternates, so where you're expecting for example {_*,} to be converted to something like (_[^/]*|) (or technically (_[^/]*)?, since the underlying regex engine doesn't support empty alternates itself), it's actually converting it to _[^/]*

@BurntSushi BurntSushi changed the title ripgrep's globbing doesn't match that of bash support empty alternate glob patterns May 8, 2020
@BurntSushi BurntSushi added the enhancement An enhancement to the functionality of the software. label May 8, 2020
ilyagr added a commit to ilyagr/ripgrep that referenced this issue Mar 9, 2021
This syntax does not exist in `git`, so it is not documented in `man gitignore`. There is
a question of whether it *should* exist, but as long as it does, it should be documented
somewhere.

See also:
BurntSushi#1221
BurntSushi#1368
BurntSushi pushed a commit that referenced this issue May 30, 2021
This syntax does not exist in `git`, so it is not documented in `man
gitignore`. There is a question of whether it *should* exist, but as
long as it does, it should be documented somewhere.

See also:
#1221
#1368

Closes #1816
BurntSushi pushed a commit that referenced this issue Jun 1, 2021
This syntax does not exist in `git`, so it is not documented in `man
gitignore`. There is a question of whether it *should* exist, but as
long as it does, it should be documented somewhere.

See also:
#1221
#1368

Closes #1816
BurntSushi pushed a commit that referenced this issue Jun 1, 2021
This syntax does not exist in `git`, so it is not documented in `man
gitignore`. There is a question of whether it *should* exist, but as
long as it does, it should be documented somewhere.

See also:
#1221
#1368

Closes #1816
zombiepigdragon added a commit to zombiepigdragon/ripgrep that referenced this issue Dec 10, 2022
Add a method GlobBuilder::empty_alternates and supporting mechanisms.

related to BurntSushi#1368
BurntSushi pushed a commit that referenced this issue Jul 8, 2023
Add a method GlobBuilder::empty_alternates and supporting mechanisms.

Ref #1368
Closes #2369
BurntSushi pushed a commit that referenced this issue Jul 8, 2023
Add a method GlobBuilder::empty_alternates and supporting mechanisms.

Ref #1368
Closes #2369
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement to the functionality of the software.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants