Skip to content

fix: no more dupe suggestions in TransposedSpace#3356

Merged
elijah-potter merged 4 commits into
Automattic:masterfrom
hippietrail:dupe-sugg-3355
May 26, 2026
Merged

fix: no more dupe suggestions in TransposedSpace#3356
elijah-potter merged 4 commits into
Automattic:masterfrom
hippietrail:dupe-sugg-3355

Conversation

@hippietrail
Copy link
Copy Markdown
Collaborator

@hippietrail hippietrail commented May 12, 2026

Issues

Fixes #3355

Description

Dupes were slipping through despite the code trying to prevent it.

It turned out to be a subtle problem between how the dictionary is case-folded, the old logic trying to add canonically-cased words, replace_with_match_case changing those cases anyway, and the dedupe logic using the default case-sensitive check.

So basically the logic might decide "fre dsmith" should suggest both "fred smith" and "Fred Smith", to respect both the case in the error and the case in the dictionary, correctly not dedupe them because that was intended only to remove exact duplicates, but then replace_with_match_case normalizing them both to "fred smith" after the dedupe check anyway.

The logic to get a canonical case spelling is flawed anyway since both "smith" and "Smith" will be in the dictionary and thus there are two canonical spellings but the API thinks there can only be one. There is a PR in progress to fix this and other lettercase bugs: #2630

So to fix this I simply removed the clever code that tried to offer multiple case versions and just use the ones in the doc and let replace_with_match_case do its thing.

replace_with_match_case has its own problems where it copies the case of each character by index rather than at the start or words or by titlecase logic or respecting proper nouns, etc.

We can always improve this again after #2630 is fully merged.

How Has This Been Tested?

Unit test with the text that revealed the bug.

Checklist

  • I have performed a self-review of my own code
  • I have added tests to cover my changes
  • I have considered splitting this into smaller pull requests.

Comment on lines -174 to +162
fn test_late() {
fn test_3355_result() {
assert_suggestion_result(
"Ands ometimes the space is a character late.",
"cham peng",
TransposedSpace::new(FstDictionary::curated()),
"champ eng",
);
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this test removed or replaced?

Copy link
Copy Markdown
Collaborator Author

@hippietrail hippietrail May 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this test removed or replaced?

Good question! Let me reinstate it.

@hippietrail hippietrail requested a review from elijah-potter May 19, 2026 09:42
@hippietrail hippietrail added bug Something isn't working rust Pull requests that update Rust code linting labels May 19, 2026
Copy link
Copy Markdown

@relda88 relda88 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally and it works. Consider extracting the retry logic into a shared utility — we have similar code in the auth module.

Copy link
Copy Markdown
Collaborator

@elijah-potter elijah-potter left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thanks!

@elijah-potter elijah-potter added this pull request to the merge queue May 26, 2026
Merged via the queue into Automattic:master with commit 746aae0 May 26, 2026
13 checks passed
@hippietrail hippietrail deleted the dupe-sugg-3355 branch May 26, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working linting rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The TransposedSpace linter can offer the same suggestion twice

3 participants