Skip to content

Fix ends_with missing overlapping suffix matches - #93

Open
gaoflow wants to merge 1 commit into
null8626:mainfrom
gaoflow:fix-ends-with-overlapping-suffix
Open

Fix ends_with missing overlapping suffix matches#93
gaoflow wants to merge 1 commit into
null8626:mainfrom
gaoflow:fix-ends-with-overlapping-suffix

Conversation

@gaoflow

@gaoflow gaoflow commented Jul 28, 2026

Copy link
Copy Markdown

ends_with is self.find(other).last().end == len, but find yields non-overlapping matches, so a real suffix that overlaps an earlier match is never emitted and the check returns false:

assert!(decancer::cure!("hahaha").unwrap().ends_with("haha")); // was false

Same for "banana".ends_with("ana") and the confusable core case cure!("bаnаnа").ends_with("ana"). starts_with is start-anchored, so it was already correct — only the ends_with sibling was affected.

Fix: scan each suffix with the same anchored is_equal that PartialEq uses, so ends_with is true iff some suffix similarly-equals the needle. Non-suffixes still return false ("hahaha".ends_with("hah")) and starts_with/contains are unchanged. Added a similar_ends_with test (overlap, repeated/separated/leetspeak/confusable suffixes, whole-string, empty, non-suffix); cargo test --all-features passes.

find() yields non-overlapping matches, so ends_with returned false for a
genuine suffix that overlaps an earlier occurrence ("hahaha".ends_with("haha")).
Scan each suffix with the same anchored is_equal check PartialEq uses, which
also keeps starts_with untouched.
@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 52 complexity

Metric Results
Complexity 52

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

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.

1 participant