Skip to content

fix(opencode): match canonically equivalent Unicode in patches - #40198

Open
leizd wants to merge 1 commit into
anomalyco:devfrom
leizd:unicode-patch-match
Open

fix(opencode): match canonically equivalent Unicode in patches#40198
leizd wants to merge 1 commit into
anomalyco:devfrom
leizd:unicode-patch-match

Conversation

@leizd

@leizd leizd commented Aug 3, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #31651

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds a final canonical Unicode-equivalence matching pass to
seekSequence().

Patch verification previously failed when the file and patch contained
visually identical text represented using different Unicode normalization
forms, such as NFC and NFD.

The existing matching passes and their order are preserved. If they all
fail, the new pass compares both lines after NFC normalization and trimming:

a.normalize("NFC").trim() === b.normalize("NFC").trim()

This deliberately uses NFC rather than NFKC, so it only handles canonical
equivalence and does not introduce compatibility or fuzzy matching.

The file contents and replacement text are not globally normalized, so the
replacement retains its original normalization form.

How did you verify your code works?

Added regression coverage for:

  • Cyrillic text with NFD file content and an NFC patch
  • Latin é with NFC file content and an NFD patch
  • Non-equivalent Unicode text continuing to fail
  • Replacement text retaining its supplied normalization form

Commands run:

bun test test/patch/patch.test.ts
23 passed, 0 failed

bun run typecheck
passed

Prettier check
passed

git diff --check
passed

Before the implementation change, the focused regression tests reproduced
Failed to find expected lines.

Screenshots / recordings

Not applicable.

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

apply_patch verification fails on canonically-equivalent Unicode — seekSequence needs an NFC pass

1 participant