Skip to content

Fix unquoted purls in printed commands (#2182) - #2204

Merged
Mikola Lysenko (mikolalysenko) merged 4 commits into
mainfrom
agent/fix-unquoted-purl-in-printed-commands
Nov 24, 2026
Merged

Mikola Lysenko (mikolalysenko) merged 4 commits into
mainfrom
agent/fix-unquoted-purl-in-printed-commands

Conversation

@mikolalysenko

@mikolalysenko Mikola Lysenko (mikolalysenko) commented Nov 23, 2026 •

Copy link
Copy Markdown
Collaborator

LLM Description written by Claude Code:claude-fable-5-2

Fixes #2182

Summary

After a hosted scan wires one gem, the update-hold note tells the user to run socket-patch rollback pkg:gem/rack@2.2.8?platform=ruby. That command does not work in any shell:

  • zsh and bash with failglob refuse it, because ? is a glob character.
  • bash with nullglob drops the argument and runs a bare socket-patch rollback, which unwinds every patch in the project.
  • A plain bash passes it on, and rollback answers No patch found matching identifier: a hosted pin is selected by its base purl, and a target with a qualifier matches only that exact key.

The note now names the pin as rollback selects it, pkg:gem/rack@2.2.8, which is also what CLI_CONTRACT.md and docs/ecosystems.md already show.

Root cause

Messages that print a command to paste interpolated a patch record's purl as is. A record's purl can carry qualifiers (?platform=ruby on every gem record, ?artifact_id=... on PyPI variants), so the printed word was neither the target the command needs nor safe to paste.

What changed

Message Before Now
Gem update-hold note (scan, get, hosted) record's purl base purl; two records of one release count as one pin
redirect_mirror_pin_not_moved warning candidate's purl base purl
patched_in_other_scope warning (rollback) manifest key, --cwd unquoted base purl (the run keeps the whole variant group, and a base purl selects it); --cwd quoted
cargo_cache_patch_kept, pypi_installed_patch_kept (scan --prune) manifest key same key, through ui::shell_word
Stale hosted pin note (list), withdrawn-patch warning (scan) pin's purl same purl, through ui::shell_word

A purl with no character a shell reads specially prints exactly as before. ui::shell_word quotes %, so a scoped npm purl (pkg:npm/%40scope/a@1.0.0) is now quoted in these messages.

CLI_CONTRACT.md ("Update hold") says the note names the pin without the record's qualifiers.

Evidence

  • gem_hold_note_names_the_gems_bundler_can_no_longer_update (unit, scan/hosted.rs): a pin recorded with ?platform=ruby is named by its base purl; two builds of one release are one pin; two versions fall back to the placeholder. Fails on the test-only commit, passes after the fix.
  • other_scope_warning_prints_a_command_a_shell_reads_as_written (unit, rollback.rs): same, plus quoting of a scoped npm purl and a --cwd with a space.
  • gem_hosted_scan_says_the_gem_is_held_at_its_version (e2e_redirect_gem_build, real Bundler): the fixture now serves the record with ?platform=ruby, as the patch service does. The test reads the rollback command from the scan's stdout, passes it through bash -O nullglob, runs the words bash produced, and checks the lock is restored byte for byte. Against the pre-fix source it fails with the note printing pkg:gem/vuln-gem@1.0.0?platform=ruby.
  • The issue's repro (rack 2.2.8, Bundler 4.0.18, Ruby 3.3.6, the repository's stand-in patch service): the scan prints socket-patch rollback pkg:gem/rack@2.2.8; pasted into bash -O nullglob it exits 0 and Gemfile.lock is byte-identical to the pre-scan lock. Before the fix the same paste left the lock rewired.

Local runs:

cargo test -p socket-patch-cli --lib                                      1042 passed
cargo test -p socket-patch-cli --test e2e_redirect_gem_build -- --ignored   54 passed (Bundler 4.0.18)
cargo test -p socket-patch-cli --test global_scope_project_state            29 passed
cargo clippy --locked -p socket-patch-cli --all-features -- -D warnings     clean

cargo clippy --all-targets reports lints in test targets this PR does not touch (tests/prebuilt_common, duplicate mod loads); they are on main and CI's clippy does not check test targets.

Review

/code-review high found nothing introduced by the diff. Two of its three findings are fixed here (the other-scope hint named one qualified key of a variant group; the e2e took the command from its own expected string instead of stdout). Not fixed:

  • The Bazel hub notice in core prints socket-patch get <purl> --mode hosted with the purl bare. A Maven purl would need a ?type=jar or ?repository_url= qualifier to be affected, the file is being changed by several open Bazel PRs, and core has no shell-quoting helper. Left for a follow-up.

For a maintainer

socket-patch rollback 'pkg:gem/rack@2.2.8?platform=ruby' (quoted, so the shell is not involved) selects no hosted pin, though that is the purl a gem's patch record carries. This PR stops printing it and does not change how targets match. Whether a qualified target should also select the hosted pin of its release is a behavior decision.

https://claude.ai/code/session_011f9aePWXPmhzYMdmsPEUee


Generated by Claude Code

Claims #2182. The fix follows in later commits.

Assisted-by: Claude Code:claude-fable-5-2
A gem record's purl carries ?platform=ruby. The hosted hold note
prints it as the rollback target, where it matches no hosted pin and
its ? is a glob character. The other-scope rollback warning prints a
manifest key unquoted. Both tests fail until the next commit.

Refs #2182

Assisted-by: Claude Code:claude-fable-5-2
The hosted gem hold note printed the patch record's purl as the
rollback target. A gem record's purl carries ?platform=ruby, which
selects no hosted pin, and its ? is a glob character: zsh refuses the
command, and bash with nullglob drops the argument and runs a bare
rollback, which unwinds every patch in the project.

The note and the mirror-pin warning now name the hosted pin by its
base purl, as rollback selects it. The other messages that print a
command with a purl (list, the withdrawn-patch warning, the prune
keep warnings, the other-scope rollback warning) pass it through
ui::shell_word, so a manifest key with qualifiers is quoted.

The gem e2e serves the record with its qualifier and runs the
printed command through a nullglob bash.

Fixes #2182

Assisted-by: Claude Code:claude-fable-5-2
The other-scope rollback warning keeps a record with its whole
variant group, so the command it prints names the base purl, which
selects that group, instead of one qualified key. The gem e2e now
reads the printed command from the scan's own output.

Refs #2182

Assisted-by: Claude Code:claude-fable-5-2
@mikolalysenko
Mikola Lysenko (mikolalysenko) marked this pull request as ready for review November 23, 2026 19:01
@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] bugbot run


Generated by Claude Code

@cursor

cursor Bot commented Nov 23, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
User-facing message and documentation fixes with added tests; no change to how rollback target matching works beyond what gets printed.

Overview
Fixes #2182: user-facing messages that suggest pasteable socket-patch rollback / remove commands no longer embed full patch-record PURLs with qualifiers (?platform=ruby, etc.).

Gem update-hold notes now name the pin the way rollback selects it—base PURL only, with quoting via ui::shell_word—and treat multiple records of one release as a single pin. The same pattern applies to other-scope rollback hints, prune GC warnings, hosted mirror / withdrawn / orphaned-resolution messages, and CLI_CONTRACT.md.

Tests lock in correct command text (unit tests in rollback and hosted) and an e2e that runs the printed rollback through bash with nullglob, using API responses that include qualified gem PURLs like production.

Reviewed by Cursor Bugbot for commit e8eae12. Configure here.

@mikolalysenko

Copy link
Copy Markdown
Collaborator Author

[agent] PR shepherd: review brief for the approver

What it does. Fixes #2182. Messages that print a command to paste used a patch record's purl as is, including qualifiers like ?platform=ruby. As a result, rollback matched no hosted pin, zsh refused the glob, and bash with nullglob dropped the argument and ran a bare rollback that unwinds every patch. These commands now name the base purl where rollback selects by base purl (the gem hold note, the mirror-pin warning, the other-scope warning). They also quote words through the existing ui::shell_word helper (including --cwd).

Risk. Low. Only message text changes, and matching is untouched. A purl with no shell-special characters prints exactly as before. A scoped npm purl (%40) is now quoted.

Look here

  • scan/hosted.rs:3294: gem hold note strips qualifiers and dedups the builds of one release before deciding "one pin"
  • scan/hosted.rs:144: mirror-pin warning
  • rollback.rs:360: other-scope warning, with base purl and quoted --cwd
  • scan/gc.rs:399, list.rs:1091: quoted only. These keep the full key because a manifest key is matched exactly, and HostedPin.purl is already a base purl.
  • [e2e_redirect_gem_build.rs:6401](https://github.com/SocketDev/socket-patch/blob/e8eae12a5d39d849abb2cdb2832b44601d1f6a30/crates/socket-patch-cli/tests/e2e_redirect_gem_build.rs#L6401): e2e that runs the printed command through bash -O nullglob

Verified

  • Read the whole diff against main. shell_word quotes ? and % on both POSIX and Windows.
  • HostedPin.purl is documented as the canonical base purl, so the list and withdrawn messages can't print a qualifier.
  • rollback already strips qualifiers when it selects hosted pins.
  • New unit tests cover a qualified gem pin, two builds of one release, two versions (placeholder) and a quoted --cwd with a space.
  • CI on e8eae12: ci-ok and clippy pass, nothing failed. No conflict, no open threads. CHANGELOG.md is untouched.

Changes I made. None.

Open questions

  • The PR's own maintainer note is a behavior decision for a separate change: should rollback 'pkg:gem/x@1?platform=ruby' (a qualified target) also select the hosted pin of its release? Today it doesn't, and this PR only stops printing that form. That question doesn't block this PR.
  • Find the Maven artifacts a pinned rules_jvm_external hub builds in scan #2191 edits the same withdrawn-pin message line (scan/withdrawn.rs). Whichever merges second will need a small merge.

Generated by Claude Code

@mikolalysenko Mikola Lysenko (mikolalysenko) added the Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review label Nov 23, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

[agent] Reviewed how rollback selects hosted pins and how the CLI renders the command. The hint now names the release, and the regression test runs the words emitted by the CLI under Bash nullglob.

Merged via the queue into main with commit 74b3306 Nov 24, 2026
83 checks passed
@mikolalysenko
Mikola Lysenko (mikolalysenko) deleted the agent/fix-unquoted-purl-in-printed-commands branch November 24, 2026 15:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Ready for review Agent-verified: mergeable, CI green, Bugbot clean — awaiting human review

Projects

None yet

3 participants