Skip to content

fix: use -- separator when passing file paths to decompression tools#3282

Open
luinbytes wants to merge 1 commit intoBurntSushi:masterfrom
luinbytes:master
Open

fix: use -- separator when passing file paths to decompression tools#3282
luinbytes wants to merge 1 commit intoBurntSushi:masterfrom
luinbytes:master

Conversation

@luinbytes
Copy link
Copy Markdown

Summary

Fixes #3222 - Files with dash-prefixed names (e.g., -10.txt.gz) were causing decompression tools to fail with errors like gzip: invalid option -- '0' when using the -z flag.

The Problem

When searching compressed files with -z, ripgrep spawns external decompression tools (gzip, bzip2, xz, etc.) and passes the file path as an argument:

gzip -d -c ./-10.txt.gz

This fails because gzip interprets -10.txt.gz as options, not a filename.

The Fix

Added -- separator before the file path to signal end of options:

gzip -d -c -- ./-10.txt.gz

Testing

Verified locally:

$ echo "test content" > ./-10.txt
$ gzip ./-10.txt
$ rg -z test .
./-10.txt.gz:test content

Changes

  • crates/cli/src/decompress.rs: Single line change to add -- separator

This is a minimal, safe fix that follows standard POSIX conventions for handling dash-prefixed filenames.

When searching compressed files with -z flag, ripgrep calls external
decompression tools (gzip, bzip2, xz, etc.) with the file path as an
argument. Files whose names start with a dash (e.g., '-10.txt.gz') were
being interpreted as command-line options by these tools, causing
errors like:

    gzip: invalid option -- '0'

This fix adds a '--' separator before the file path, which signals to
the decompression tools that subsequent arguments are filenames, not
options.

Fixes BurntSushi#3222
@luinbytes
Copy link
Copy Markdown
Author

luinbytes commented Mar 19, 2026

Hi! Friendly bump on this. Happy to make changes if anything needs adjusting. No rush, just checking it hasn't been missed. Thanks!

@jafd
Copy link
Copy Markdown

jafd commented Mar 24, 2026

Prior art: #3224

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.

Calls to compression tools need to separate file names from options

2 participants