Skip to content

Fixed a crash in ContentSearchService with combining grapheme clusters - #878

Open
mickael-menu wants to merge 1 commit into
developfrom
fix-issue-876
Open

Fixed a crash in ContentSearchService with combining grapheme clusters#878
mickael-menu wants to merge 1 commit into
developfrom
fix-issue-876

Conversation

@mickael-menu

Copy link
Copy Markdown
Member

Fixed

Shared

  • #876 Fixed a crash (String index is out of bounds) in ContentSearchService when searching a publication containing characters merging with the surrounding text, such as combining diacritical marks.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a crash in ContentSearchService triggered by grapheme-cluster regrouping (e.g., leading combining marks / variation selectors) that could cause out-of-bounds String indexing while computing match/snippet ranges.

Changes:

  • Adjusts sliding-window bookkeeping in ContentSearchService.Iterator to avoid relying on additive character counts that can drift when Swift regroups grapheme clusters across concatenation boundaries.
  • Adds defensive, bounds-checked conversions from window offsets to String.Index to prevent String.index(_:offsetBy:) traps during trimming, searching, and locator/snippet construction.
  • Adds regression tests covering content that starts with combining marks / variation selectors and updates the changelog entry for #876.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
Tests/SharedTests/Publication/Services/Search/ContentSearchServiceTests.swift Adds regression tests for crash scenarios involving grapheme-cluster boundary regrouping.
Sources/Shared/Publication/Services/Search/ContentSearchService.swift Makes window offset → index conversions safe and updates window count handling to avoid out-of-bounds indexing.
CHANGELOG.md Documents the crash fix under Unreleased (Shared) with a reference to #876.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +352 to +354
private func windowIndex(at offset: Int) -> String.Index? {
windowText.index(windowText.startIndex, offsetBy: offset, limitedBy: windowText.endIndex)
}
@mickael-menu
mickael-menu changed the base branch from swift6 to develop August 5, 2026 14:25
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.

2 participants