fix(rg): search piped stdin when no paths are given#281
Open
mohan-garimella wants to merge 1 commit into
Open
Conversation
|
Someone is attempting to deploy a commit to the Vercel Labs Team on Vercel. A member of the Team first needs to authorize it. |
Author
|
Addressed in 15f5d15 — added a |
Contributor
|
Please sign commits |
When rg receives piped stdin with no explicit path arguments, it now searches stdin instead of defaulting to the current directory. This matches real ripgrep behavior and is consistent with how grep already handles stdin in just-bash. The fix checks for non-empty stdin before defaulting to ".". When stdin has content and no paths are given, searchContent is called directly on the stdin text with all applicable options (invert, count, context, etc). Also fixes the existing rg.utf8-stdin test which was previously passing by accident — it tested piped stdin but rg was actually searching the filesystem. Fixes vercel-labs#280
cb17b37 to
30de8fc
Compare
Author
|
@cramforce Done, Please review. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When
rgreceives piped stdin with no explicit path arguments, it ignores stdin and defaults to recursively searching the current working directory (.). This is inconsistent with real ripgrep and with howgrepalready handles stdin in just-bash.Reproduction
Fix
After building the regex, check for non-empty stdin before defaulting to
.. When stdin has content and no paths are given,searchContentis called directly on the stdin text with all applicable options (invert, count, context, quiet,-l, etc.).Also fixes
rg.utf8-stdin.test.tswhich was previously passing by accident — it testedcat /in.txt | rg '한글'but rg was actually finding the match by searching the filesystem (it foundin.txt), not by reading stdin.Tests
Fixes #280