Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions stdlib/public/core/UnicodeHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,13 @@ extension _StringGuts {
return String.Index(_encodedOffset: idx._encodedOffset)._scalarAligned
}
if _slowPath(self.isForeign) {
// In 5.1 this check was added to foreignScalarAlign, but when this is
// emitted into a client that then runs against a 5.0 stdlib, it calls
// a version of foreignScalarAlign that doesn't check for this, which
// ends up asking CFString for its endIndex'th character, which throws
// an exception. So we duplicate the check here for back deployment.
guard idx._encodedOffset != self.count else { return idx._scalarAligned }

let foreignIdx = foreignScalarAlign(idx)
_internalInvariant_5_1(foreignIdx._isScalarAligned)
return foreignIdx
Expand Down