File tree Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Expand file tree Collapse file tree 1 file changed +7
-0
lines changed Original file line number Diff line number Diff line change @@ -186,6 +186,13 @@ extension _StringGuts {
186
186
return String . Index ( _encodedOffset: idx. _encodedOffset) . _scalarAligned
187
187
}
188
188
if _slowPath ( self . isForeign) {
189
+ // In 5.1 this check was added to foreignScalarAlign, but when this is
190
+ // emitted into a client that then runs against a 5.0 stdlib, it calls
191
+ // a version of foreignScalarAlign that doesn't check for this, which
192
+ // ends up asking CFString for its endIndex'th character, which throws
193
+ // an exception. So we duplicate the check here for back deployment.
194
+ guard idx. _encodedOffset != self . count else { return idx. _scalarAligned }
195
+
189
196
let foreignIdx = foreignScalarAlign ( idx)
190
197
_internalInvariant_5_1 ( foreignIdx. _isScalarAligned)
191
198
return foreignIdx
You can’t perform that action at this time.
0 commit comments