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

Option --files does not work because a pattern is always sent to rg #13

Open
vgadoury opened this issue Sep 28, 2022 · 0 comments
Open

Comments

@vgadoury
Copy link

Describe the bug
The option --riles (rg.files()) does not work because a pattern is always sent to ripgrep. From the ripgrep usage, the --files option must be used without a pattern, and all additional arguments are considered as paths:

rg [OPTIONS] --files [PATH ...]

To Reproduce

>>> from ripgrepy import Ripgrepy
>>> Ripgrepy("", "./ripgrepy/").files().run()
: The system cannot find the path specified. (os error 3)

>>> res = Ripgrepy("", "./ripgrepy/").files().run()
>>> res.command
['rg', '--files', '', './ripgrepy/']
>>> # Running the command `rg --files "" ./ripgrepy/` gives the same error:
>>> import subprocess
>>> subprocess.run(['rg', '--files', '', './ripgrepy/'])
: The system cannot find the path specified. (os error 3)
./ripgrepy/__pycache__\__init__.cpython-38.pyc
./ripgrepy/__init__.py
CompletedProcess(args=['rg', '--files', '', './ripgrepy/'], returncode=2)

Expected behavior

>>> # We should run `rg --files ./ripgrepy/` instead:
>>> subprocess.run(['rg', '--files', './ripgrepy/'])
./ripgrepy/__pycache__\__init__.cpython-38.pyc
./ripgrepy/__init__.py
CompletedProcess(args=['rg', '--files', './ripgrepy/'], returncode=0)

The expected output would be:

>>> Ripgrepy("", "./ripgrepy/").files().run()
./ripgrepy/__pycache__\__init__.cpython-38.pyc
./ripgrepy/__init__.py

>>> Ripgrepy("", "./ripgrepy/").files().run().as_string
'./ripgrepy/__pycache__\\__init__.cpython-38.pyc\n./ripgrepy/__init__.py\n'

Desktop:

  • OS: tested on Windows 10, but rg --files returns the same "os error 2" on Ubuntu when providing a non-path argument.
  • Python Version 3.8.5

Additional context
I'll send a PR shortly. I guessed it was better to explain the issue before posting a PR?

vgadoury added a commit to vgadoury/ripgrepy that referenced this issue Sep 28, 2022
Fix issue securisec#13 and emptying the pattern when using `files()`, and by preventing adding empty the patterns and path to the command.
This also fixes the options `type_list()` and `regexp(pattern)`. 

I did it this way because it seems to be what was already expected in the code for type_list() and regexp(pattern).

This PR would prevent creating an object with the arguments to "search for an empty pattern" (i.e. before this change, `Ripgrepy("", ".").run()` valid and equivalent to `rg "" "."`, which is equivalent to `rg --regexp "" "."`.). This basically matches everything, which I guess could be useful (combined with other options) to list the full content of non-ignored searched files in the same format as a pattern-search. But I would doubt that someone currently depends on this "feature" from Ripgrepy... Note thatt it would still be possible to search for this explicitly with `regexp("")`.
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

1 participant