wordpress-mobile / AztecEditor-iOS

A reusable native iOS visual HTML text editor component.
Mozilla Public License 2.0
611 stars 146 forks source link

Use NSString.paragraphRange method due to iOS 17 crash #1373

Closed twstokes closed 10 months ago

twstokes commented 10 months ago

Fixes #1374

Addresses a crash that occurs when calling String.paragraphRange(for:). The workaround for now is to call the NSString equivalent.

Related issue: https://github.com/wordpress-mobile/WordPress-iOS/issues/21261

Xcode 16 Playground code that will reproduce the crash:

import Foundation

/// Fails when using Xcode 16.0 beta 8 Playground and when running on iOS 17 beta.
let paragraphSeparator = "\u{2029}"

/// Try adding a character before or after the separator - it should not crash.
let string = paragraphSeparator
let range = string.startIndex ..< string.endIndex

/// Throws an exception.
let outRange = string.paragraphRange(for: range)
/// Success if this was reached.
print(string)

To test:

  1. Run the AztecExample demo app in the Simulator or on a real device running iOS 17
  2. Tap "Standard Demo"
  3. Place the cursor at the end of the top line "Welcome to Aztec"
  4. Erase characters until there are no more to erase
  5. Expect: No exception is thrown and the app doesn't crash.

Repeat the test for iOS 16.