From 3e2aabe03db965ab659bc51aca4cdbf74a986016 Mon Sep 17 00:00:00 2001 From: Zoltan Kochan Date: Sat, 5 Sep 2026 21:49:52 +0200 Subject: [PATCH] fix(patching): accept CRLF patch files (#14584) Update `diffy` to 0.5.2 so pnpm v12 can parse patch file headers with CRLF line endings. Add a regression test that applies a CRLF-encoded patch to an LF target file. Fixes pnpm/pnpm#14557. --- .changeset/quiet-patches-crlf.md | 5 +++++ Cargo.lock | 4 ++-- pnpm/crates/patching/src/apply/tests.rs | 21 +++++++++++++++++++++ 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 .changeset/quiet-patches-crlf.md diff --git a/.changeset/quiet-patches-crlf.md b/.changeset/quiet-patches-crlf.md new file mode 100644 index 0000000000..4d85ed9ddf --- /dev/null +++ b/.changeset/quiet-patches-crlf.md @@ -0,0 +1,5 @@ +--- +"pacquet": patch +--- + +`pnpm install` now applies patch files with CRLF line endings [pnpm/pnpm#14557](https://github.com/pnpm/pnpm/issues/14557). diff --git a/Cargo.lock b/Cargo.lock index c1a409bfc0..67d8e7a454 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1667,9 +1667,9 @@ checksum = "6184e33543162437515c2e2b48714794e37845ec9851711914eec9d308f6ebe8" [[package]] name = "diffy" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "10aec8f7f9393bd6a4f2762be0ceb012d3cbe2478987258cc9960de148561914" +checksum = "3e3dc2f773b6aaa63b1a7684b8589f670a8a0146a510b74d23a401c882364b49" dependencies = [ "hashbrown 0.17.0", ] diff --git a/pnpm/crates/patching/src/apply/tests.rs b/pnpm/crates/patching/src/apply/tests.rs index 3970a7a469..8d65f64c2c 100644 --- a/pnpm/crates/patching/src/apply/tests.rs +++ b/pnpm/crates/patching/src/apply/tests.rs @@ -90,6 +90,27 @@ fn applies_modify_against_existing_file() { assert_eq!(after, IS_POSITIVE_INDEX_JS_PATCHED); } +#[test] +fn applies_patch_with_crlf_line_endings() { + let patched = tempdir().unwrap(); + let target = patched.path().join("file.txt"); + fs::write(&target, "one\ntwo\n").unwrap(); + let patch_dir = tempdir().unwrap(); + let hunk = text_block_fnl! { + "@@ -1,2 +1,3 @@" + " one" + "+added" + " two" + }; + let crlf_patch = format!("{FILE_TXT_PATCH_HEADER}{hunk}").replace('\n', "\r\n"); + let patch = write_patch(patch_dir.path(), &crlf_patch); + + apply_patch_to_dir(patched.path(), &patch).expect("apply must succeed"); + + let after = fs::read_to_string(target).unwrap(); + assert_eq!(after, "one\nadded\r\ntwo\n"); +} + #[test] fn applies_an_insertion_with_context_on_both_sides() { let original = text_block_fnl! {