Open lorentey opened 2 years ago
@swift-ci create
This is because one of the `replaceSubrange` implementations on the standard, generic `Slice` type assumes that indices before the replaced range remain valid after the replacement.
`replaceSubrange` is documented to invalidate all indices, no matter where they are in relation to the replaced range.
In this particular case, the bridged string measures index offsets in UTF-16 code units, but it gets converted to a UTF-8 native string as a side effect of the mutation. `Slice.replaceSubrange` fails to update the `startIndex`, and the old index offset gets reinterpreted in UTF-8.
`Slice.replaceSubrange` needs to always recalculate the bounds from scratch. (This will sadly regress performance in the usual case, but it is unavoidable for correctness.)
Environment
- All shipping Swift releases since at least 5.0 - Swift main as of 2022-03-30Additional Detail from JIRA
| | | |------------------|-----------------| |Votes | 0 | |Component/s | Standard Library | |Labels | Bug | |Assignee | None | |Priority | Medium | md5: 18f92a6c21179306e3e4f10b69940880Issue Description: