Vendored gem mode writes the rewired `gem` line of a CRLF Gemfile with an LF ending, leaving the Gemfile with mixed line endings
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 25/100
Rechercherichtung
Start with crates/socket-patch-core/src/vendor/gem.rs, especially plan_gemfile_edit, apply_gemfile_plan, and the Append arm; the report also points to restore_gemfile_line. Reproduce with the CRLF Gemfile case in crates/socket-patch-cli/tests/e2e_vendor_gem_build.rs and verify the rewritten line retains CRLF. A pull request is already open for this issue.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
[agent] Found by the scheduled Bundler (RubyGems) bug-hunt routine (ledger #316).
Summary
When vendored mode rewires a gem declaration in a CRLF Gemfile, the new gem "x", "<ver>", path: "…" line is written with a bare \n. Every other line keeps \r\n. So after socket-patch vendor the Gemfile has mixed line endings:
source "https://rubygems.org"\r\n
\r\n
gem "rack", "3.2.7", path: ".socket/vendor/gem/<uuid>/rack-3.2.7"\n <- was "...\"~> 3.1\"\r\n"
vendor --revert, rollback and remove restore the recorded original line (with its \r), so the round trip is byte-exact. The vendored state in between is the problem. Bundler parses the file fine, so installs and bundle exec aren't affected.
This is separate from #1808, which is about the CRLF Gemfile.lock (the lock surgery). Its fix PR #1811 only touches the lock path and doesn't change the Gemfile line.
Impact
- A project that commits its
Gemfileas CRLF (.gitattributes-textoreol=crlfwith a non-normalizing checkout, or Windows editors withautocrlf=false) commits a mixed-endingGemfileafter vendoring. The diff shows an EOL change on top of the real edit, and RuboCopLayout/EndOfLine(crlf/nativeon Windows) flags the line. - This is inconsistent with hosted mode, which keeps a CRLF
GemfileCRLF (gemfile_rerun_on_crlf_checkout_never_nests), and with the CRLF-preservation fixes the vendored backends got for other manifests (#662 pnpmpackage.json, #1567 requirements.txt).
Severity is low: the file still works. It's a correctness and hygiene defect in a user-owned manifest.
Repro
This is a scratch addition to gem_vendor_fresh_checkout_bundle_install_and_revert in crates/socket-patch-cli/tests/e2e_vendor_gem_build.rs, with a real bundle install from rubygems.org and the patch staged offline with stage_patch_with_vuln:
Gemfile (CRLF): source "https://rubygems.org"\r\n\r\ngem "rack", "~> 3.1"\r\n
bundle config set --local path vendor/bundle && bundle install # Gemfile.lock stays LF
# stage a lib/rack.rb patch for pkg:gem/[email protected]
socket-patch vendor --json --offline # exit 0, applied 1
ruby -e 'p File.binread("Gemfile")'
# => "source \"https://rubygems.org\"\r\n\r\ngem \"rack\", \"3.2.7\", path: \".socket/vendor/gem/<uuid>/rack-3.2.7\"\n"
socket-patch vendor --revert --json # (or rollback / remove <purl>) -> Gemfile byte-exact CRLF again
Expected vs actual
- Expected: a rewritten line keeps the line ending of the line it replaces (or
utils::line_endings::terminatorof the file), as hosted mode does for the sameGemfile. docs/ecosystems.md lists the vendoredGemfile+Gemfile.lockpair edit as supported, with no line-ending caveat, and #815 / #1108 set one terminator rule for lines a writer inserts. - Actual: the rewired line ends in
\ninside a CRLF file.
Matrix (Linux, Ruby 3.3.6; the edit is pure text handling, so it doesn't depend on the OS)
| Case | Bundler 2.6.9 | Bundler 4.0.23 |
|---|---|---|
vendor on CRLF Gemfile + LF lock: vendored Gemfile has mixed endings |
fail (×3) | fail (×3) |
… then vendor --revert / rollback / remove: Gemfile and lock byte-exact |
pass | pass |
LF Gemfile (control) |
pass | pass |
macOS / Windows probes are unavailable (push-triggered probe runs don't start, see #316). Tested on main ecd4924 (v5.0.1).
Suspect code
crates/socket-patch-core/src/vendor/gem.rs:1346-1360(plan_gemfile_edit):new_lineis built from scratch (format!("gem {q}{name}{q}, …")) whileoriginal_lineislines[idx]fromtext.split('\n'), so it still carries the\r. The new line drops it unless a trailing comment happens to carry it.apply_gemfile_plan(gem.rs:1610-1633) then joins with\n.- The
RewireOursarm keeps the\r(replacenon the original), and theAppendarm (transitive gem,GemfilePlan::Append { block }) appends an LF-only block. I didn't run theAppendarm here. - A related shape I saw (not filed separately): after a vendored LF pair is re-checked-out as CRLF,
restore_gemfile_line(gem.rs:2403) writes back the recorded LF original into the CRLF file. With #1811 applied,vendor --reverton such a checkout then leaves theGemfilemixed as well (…\r\n\r\ngem "rack", "~> 3.1"\n).
- Vorherrschende Sprache
- Rust
- Sterne
- 8
- Forks
- 2
- Ø Merge
- 19 Std. 31 Min.
- Gemergte PRs (30 T.)
- 686
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Keine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus SocketDev/socket-patch
-
bug bughunt pm:npm
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 53/100
SocketDev/socket-patch#1827 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
Go apply, apply --check and vex treat a module that is only another module's replace target as built, so the patch is reported applied and attested while go builds the unpatched codeEvtl. vergeben @mikolalysenko hat das heute übernommen. Offenagent:claimed agent:triaged bug bughunt pm:go priority:p2
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 48/100
SocketDev/socket-patch#1823 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
CI perf: workflow_dispatch of CI — Windows-only janitor fixes re-run the full Linux + macOS nightly matrix (~100 min/day, ~30 macOS)Evtl. vergeben @mikolalysenko hat das vor 1 Tag übernommen. Offenagent:claimed agent:triaged ci-perf priority:p3
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 1/100
SocketDev/socket-patch#1818 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Nightly Windows: 3 Go workspace unit tests fail (Unix-only GOWORK paths)Evtl. vergeben @mikolalysenko hat das vor 1 Tag übernommen. Offenagent:claimed agent:triaged ci-janitor priority:p3
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 35/100
SocketDev/socket-patch#1815 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
Go apply writes the shared replace into ./go.work when GOWORK names another file in the same directory, reports success, and the workspace builds unpatchedEvtl. vergeben @mikolalysenko hat das vor 1 Tag übernommen. Offenagent:claimed agent:triaged bug bughunt pm:go priority:p2
Schwierigkeit 4/5 1-2 Tage Anfängerfreundlichkeit 35/100
SocketDev/socket-patch#1810 · 3 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in SocketDev/socket-patch
Ähnliche Issues
-
priority middle
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 62/100
KATO-Hiro/AtCoderClans#12940 ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 83/100
Maintainer antworten meist innerhalb von 1 Tag
-
o8 next debug build aborts on Glass to Dark appearance switch (nil identifier messaged before check)Offenbug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
hurttlocker/o8#5112 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 79/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 1 Tag