Skip to content

Commit b29d8f4

Browse files
committed
[stdlib] Substring: restrict grapheme breaking to the bounds of the substring
(Oops)
1 parent 9714f97 commit b29d8f4

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

stdlib/public/core/StringGraphemeBreaking.swift

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,13 @@ extension _StringGuts {
130130
if i == bounds.lowerBound || i == bounds.upperBound { return i }
131131

132132
let offset = i._encodedOffset
133-
let prior = offset - _opaqueCharacterStride(endingAt: offset)
134-
let stride = _opaqueCharacterStride(startingAt: prior)
133+
134+
let offsetBounds = Range(
135+
_uncheckedBounds: (
136+
bounds.lowerBound._encodedOffset, bounds.upperBound._encodedOffset))
137+
138+
let prior = offset - _opaqueCharacterStride(endingAt: offset, in: offsetBounds)
139+
let stride = _opaqueCharacterStride(startingAt: prior, in: offsetBounds)
135140
_internalInvariant(offset <= prior + stride,
136141
"Grapheme breaking inconsistency")
137142
if offset >= prior + stride {

0 commit comments

Comments
 (0)