Skip to content

fix(rg): search piped stdin when no paths are given#281

Open
mohan-garimella wants to merge 1 commit into
vercel-labs:mainfrom
mohan-garimella:fix/rg-stdin-search
Open

fix(rg): search piped stdin when no paths are given#281
mohan-garimella wants to merge 1 commit into
vercel-labs:mainfrom
mohan-garimella:fix/rg-stdin-search

Conversation

@mohan-garimella

Copy link
Copy Markdown

Summary

When rg receives 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 how grep already handles stdin in just-bash.

Reproduction

# rg ignores stdin, searches cwd instead
echo "hello world" | rg "hello"
# Expected: hello world
# Actual: recursively searches . and returns all file matches containing "hello"

# grep handles stdin correctly
echo "hello world" | grep "hello"
# Output: hello world ✅

Fix

After building the regex, check 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, quiet, -l, etc.).

Also fixes rg.utf8-stdin.test.ts which was previously passing by accident — it tested cat /in.txt | rg '한글' but rg was actually finding the match by searching the filesystem (it found in.txt), not by reading stdin.

Tests

  • 7 new stdin-specific tests covering: basic piped search, no-match exit code, case-insensitive, inverted match, count mode, explicit-path-overrides-stdin, and multibyte UTF-8
  • All 515 existing rg tests pass (82 skipped)
  • All 205 existing grep tests pass (8 skipped)

Fixes #280

@vercel

vercel Bot commented Jun 29, 2026

Copy link
Copy Markdown

Someone is attempting to deploy a commit to the Vercel Labs Team on Vercel.

A member of the Team first needs to authorize it.

Comment thread packages/just-bash/src/commands/rg/rg-search.ts
@mohan-garimella

Copy link
Copy Markdown
Author

Addressed in 15f5d15 — added a stdinConsumedByPatternFile guard that skips the stdin search path when -f - was used. Also added a test for echo "hello" | rg -f - /data.txt to ensure patterns from stdin are used against the explicit file, not searched as content.

@cramforce

Copy link
Copy Markdown
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
@mohan-garimella

Copy link
Copy Markdown
Author

@cramforce Done, Please review.

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

Successfully merging this pull request may close these issues.

rg ignores piped stdin and searches cwd instead

2 participants