Skip to content

fix(wget): detect -O - in trailing args absorbed by Clap - #793

Open
gghez wants to merge 4 commits into
rtk-ai:developfrom
gghez:fix/wget-dash-o-flag-parsing
Open

gghez wants to merge 4 commits into
rtk-ai:developfrom
gghez:fix/wget-dash-o-flag-parsing

Conversation

@gghez

@gghez gghez commented Mar 24, 2026

Copy link
Copy Markdown

Summary

When flags like --no-check-certificate precede -O -, Clap's trailing_var_arg absorbs all remaining tokens into the args vec, leaving the output field as None. This caused RTK to route through run() instead of run_stdout(), so the bare - was passed to wget as a positional URL argument — producing:

example.com FAILED: Prepended http:// to '-'

I added two helper functions in wget_cmd.rs:

  • has_stdout_output_flag() — scans trailing args for -O - / -O- / --output-document - / --output-document=-
  • strip_output_flag() — removes those tokens so they aren't duplicated when run_stdout() adds its own -O -

The routing in main.rs now checks both the Clap-parsed output field and the trailing args before deciding which path to take.

Tested with:

  • rtk wget https://example.com -O - (already worked)
  • rtk wget https://example.com --no-check-certificate -O - (was broken, now fixed)
  • rtk wget -O - https://example.com (already worked)
  • rtk wget https://example.com (no regression, still downloads to file)

14 unit tests added covering all -O flag variants and edge cases.

Fixes #716

@CLAassistant

CLAassistant commented Mar 24, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@pszymkowiak pszymkowiak added bug Something isn't working effort-small Quelques heures, 1 fichier labels Mar 24, 2026
@pszymkowiak

Copy link
Copy Markdown
Collaborator

[w] wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Fixes a bug where -O - (stdout output flag) was misinterpreted as a URL argument when preceded by other flags like --no-check-certificate, because Clap's trailing_var_arg absorbed the tokens. Adds helper functions to detect and strip the stdout output flag from trailing args, and updates routing logic accordingly.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #716


Analyzed automatically by wshm · This is an automated analysis, not a human review.

@aeppling

Copy link
Copy Markdown
Contributor

Hey

We are cleaning up the codebase and improving the project structure for better onboarding. As part of this effort, PR #826 reorganizes src/ from a flat layout into subfolders.

No logic changes — only file moves and import path updates.

What you need to do

Rebase your branch on develop when receiving this comment:

git fetch origin && git rebase origin/develop

Git detects renames automatically. If you get import conflicts, update the paths:

use crate::git;        // now: use crate::cmds::git::git;
use crate::tracking;   // now: use crate::core::tracking;
use crate::config;     // now: use crate::core::config;
use crate::init;       // now: use crate::hooks::init;
use crate::gain;       // now: use crate::analytics::gain;

Need help rebasing? Tag @aeppling

When flags like --no-check-certificate precede -O -, Clap's
trailing_var_arg absorbs all remaining tokens into the args vec,
leaving the output field as None. This caused RTK to route through
run() instead of run_stdout(), so the bare "-" was passed to wget
as a positional URL argument.

Scan trailing args for -O - / -O- / --output-document - patterns
and strip them before routing to run_stdout().

Fixes rtk-ai#716

Signed-off-by: gghez <[email protected]>
@gghez
gghez force-pushed the fix/wget-dash-o-flag-parsing branch from 7c457c6 to 7ec2d29 Compare March 27, 2026 00:23
@gghez

gghez commented Mar 27, 2026

Copy link
Copy Markdown
Author

Rebased! Only conflict was in CHANGELOG.md, the rest applied cleanly. Tests pass.

gghez and others added 3 commits April 24, 2026 23:01
…ag-parsing

# Conflicts:
#	CHANGELOG.md
#	src/cmds/cloud/wget_cmd.rs
#	src/main.rs
Routing moved from src/main.rs to src/lib.rs on develop; port the
-O - detection there.
- Use arg_tokenizer with wget's value-taking flags (from wget --help,
  GNU Wget 1.25) instead of a string scan, as src/cmds/README.md asks.
- Catches clustered short flags after the URL: 'wget URL -qO-' still
  lost the page; '-qO-' is now stripped to '-q'.
- A '-' that is another flag's value (--header -, -U -O-) or follows
  '--' no longer counts as stdout output.
- cargo fmt under style edition 2024; collapsible if fixed.

@pszymkowiak pszymkowiak left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @gghez, sorry this sat for seven months without a review. The bug is still there on develop: rtk wget https://example.com --no-check-certificate -O - prints example.com ok | - | ? instead of the page.

I've pushed two commits to your branch:

  • merged develop and moved the check to src/lib.rs (routing left main.rs)
  • has_stdout_output_flag / strip_output_flag now go through arg_tokenizer with wget's value-taking flags (from wget --help), which develop asks for now. That also catches wget URL -qO-, which your version missed (-qO- becomes -q), and stops treating a - that belongs to another flag (--header -) as stdout.
  • fmt under the 2024 style edition, one clippy fix, 4 more tests

Checked against real wget on 9 commands: stdout matches plain wget byte for byte in every case (develop loses the page in 5 of them). Full test suite passes.

Approving, thanks for the fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working effort-small Quelques heures, 1 fichier ready-for-merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: rtk wget interprets -O - flag as URL

5 participants