From 6ec17e5d555cf0dadaa51e31cfcd90ed26e24283 Mon Sep 17 00:00:00 2001 From: Aiden Cline <63023139+rekram1-node@users.noreply.github.com> Date: Tue, 21 Jul 2026 13:47:52 -0500 Subject: [PATCH] fix(core): align patch Unicode matching (#38160) --- packages/core/test/patch.test.ts | 16 ++++++++++++++++ packages/util/src/patch.ts | 1 - 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/packages/core/test/patch.test.ts b/packages/core/test/patch.test.ts index 7717c6bc665..d3ff40b7869 100644 --- a/packages/core/test/patch.test.ts +++ b/packages/core/test/patch.test.ts @@ -200,6 +200,22 @@ describe("Patch", () => { ) }) + test("does not normalize ellipses", () => { + expect(() => + Patch.derive("ellipsis.txt", [{ oldLines: ["wait..."], newLines: ["done"] }], "wait…\n"), + ).toThrow("Failed to find expected lines") + }) + + test("prefers a later exact match over an earlier normalized match", () => { + expect( + Patch.derive( + "quotes.txt", + [{ oldLines: ['He said "hello"'], newLines: ['He said "goodbye"'] }], + 'He said “hello”\nmiddle\nHe said "hello"\n', + ).content, + ).toBe('He said “hello”\nmiddle\nHe said "goodbye"\n') + }) + test("matches EOF-anchored chunks from the end", () => { expect( Patch.derive( diff --git a/packages/util/src/patch.ts b/packages/util/src/patch.ts index e969dfd6afc..d3aeb73fd91 100644 --- a/packages/util/src/patch.ts +++ b/packages/util/src/patch.ts @@ -228,7 +228,6 @@ const normalize = (value: string) => .replace(/[‘’‚‛]/g, "'") .replace(/[“”„‟]/g, '"') .replace(/[‐‑‒–—―−]/g, "-") - .replace(/…/g, "...") .replace(/[\u00A0\u2002-\u200A\u202F\u205F\u3000]/g, " ") const splitBom = (text: string) => text.startsWith("\uFEFF") ? { bom: true, text: text.slice(1) } : { bom: false, text }