Skip to content

A combining mark between two copies of a letter stops the camelCase copy taking the match: Score("Addres̃sSpace","sp") = -4 but Score("AddressSpace","sp") = 12 (#114 returns via #139) #142

Closed

Description

@matt-edmondson

What's wrong

ContinuesRun (FuzzySearch/Fuzzy.cs:376) decides whether a rematched letter "only follows its own copy" (the #114 fix) by code-unit adjacency:

bool followsOwnCopy = rematch && !nextMatch && bestLetterIdx is not null && bestLetterIdx.Value + bestLetterLength == strIdx;

Since #139, SkipUnmatchedMarks steps over combining marks. When a mark sits between the two copies, strIdx lands past bestLetterIdx + bestLetterLength. The doubled letter then counts as continuing a run, and displacesRun stops the later camelCase or separator copy from replacing it. That is the #114 failure again, on the combining-mark path, and it breaks #139's rule that an unmatched mark costs and earns nothing ("q̃Bar costs and earns what qBar does").

Reproduction (HEAD 19f2630; U+0303 doesn't compose with Q or s under NFC, so it survives normalization)

Fuzzy.Contains("AQqQ", "q", out int a);              // 12
Fuzzy.Contains("AQ̃qQ", "q", out int b);        // 2   (expected 12)
Fuzzy.Contains("AddressSpace", "sp", out int c);     // 12
Fuzzy.Contains("Addres̃sSpace", "sp", out int d); // -4  (expected 12)
Fuzzy.Contains("Addres̃Space", "sp", out int e);  // 12

A randomized check that inserted U+0332 after one letter (which should never change the score) found many more cases, all of this shape.

Why it matters

Decomposed text in scripts whose letter-plus-mark has no precomposed form (Yoruba ẹ́, Lithuanian, x̄) scores 10–16 points lower than the same text without the mark. That is enough to reorder results.

Suggested fix

Decide followsOwnCopy from the index of the previous scored codepoint, not from code-unit adjacency. Track a prevScoredIdx at the end of each loop iteration and test bestLetterIdx == prevScoredIdx. Or compare SkipUnmatchedMarks(subject, bestLetterIdx + bestLetterLength, …) with strIdx.

Acceptance criteria

  • Score("AQ̃qQ","q") == Score("AQqQ","q") and Score("Addres̃sSpace","sp") == Score("AddressSpace","sp").
  • A property test: inserting a non-composing combining mark after any subject letter leaves the score unchanged.

Activity

  1. added
    bug
    on Nov 12, 2026
  2. matt-edmondson commented on Nov 12, 2026

    @matt-edmondson
    ContributorAuthor

    Triage


    Generated by Claude Code

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

Metadata

Metadata

Labels

bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions