Fixed a crash in ContentSearchService with combining grapheme clusters - #878
Open
mickael-menu wants to merge 1 commit into
Open
Fixed a crash in ContentSearchService with combining grapheme clusters#878mickael-menu wants to merge 1 commit into
ContentSearchService with combining grapheme clusters#878mickael-menu wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
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.Iteratorto 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.Indexto preventString.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) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixed
Shared
String index is out of bounds) inContentSearchServicewhen searching a publication containing characters merging with the surrounding text, such as combining diacritical marks.