Skip to content

fix: add -- separator before filename in compression tools#3314

Open
mango766 wants to merge 1 commit intoBurntSushi:masterfrom
mango766:fix/compression-tools-dash-separator
Open

fix: add -- separator before filename in compression tools#3314
mango766 wants to merge 1 commit intoBurntSushi:masterfrom
mango766:fix/compression-tools-dash-separator

Conversation

@mango766
Copy link
Copy Markdown

When searching compressed files with names that start with a dash (e.g., -10.txt.gz), ripgrep fails because the compression tool interprets the filename as command options.

Here's the issue that this PR addresses:

$ echo "hello" > ./-10.txt
$ gzip ./-10.txt
$ rg -z .
gzip: invalid option -- '0'
Try `gzip --help' for more information.

This happens because ripgrep calls compression tools like gzip -d -c -10.txt.gz, where -10.txt.gz gets parsed as invalid options.

The fix is simple: add -- before the filename argument. This is the standard POSIX "end of options" marker that tells the tool everything following it should be treated as positional arguments, not options.

After this fix:

$ echo "hello" > ./-10.txt
$ gzip ./-10.txt
$ rg -z hello
-10.txt.gz:1:hello

This aligns with how most shell commands handle filenames that might be confused with options.

Fixes #3222

When decompressing files with names starting with a dash (e.g., -10.txt.gz),
tools like gzip interpret the filename as options. Adding '--' before the
filename follows POSIX end-of-options convention to prevent this misinterpretation.

Fixes BurntSushi#3222

Co-Authored-By: Claude (GLM-4.7) <noreply@anthropic.com>
@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