wordpress-mobile / AztecEditor-iOS

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

aDecoder.decodeInteger on nullable int causes crash #1331

Open tipa opened 3 years ago

tipa commented 3 years ago

In my fork, I disabled html pasting, which causes a crash when the user tries to copy-paste lists. This is because Aztec might encode a nil-int when performing the copy: https://github.com/wordpress-mobile/AztecEditor-iOS/blob/e0cb3c96ada0bed9fab5d3e93952e8375b29d97e/Aztec/Classes/TextKit/ParagraphProperty/TextList.swift#L83

Now, when pasting, a crash occurs here because it expects a non-nil-int: https://github.com/wordpress-mobile/AztecEditor-iOS/blob/e0cb3c96ada0bed9fab5d3e93952e8375b29d97e/Aztec/Classes/TextKit/ParagraphProperty/TextList.swift#L64

This can be fixed by changing that line to:

let decodedStart = aDecoder.decodeObject(forKey: AttributeType.start.rawValue) as? Int
SergioEstevao commented 2 years ago

Hi there, first of all thanks for the great bug report, do you want to submit a PR for the fix? I will review it and approve it if all goes well. It will also be great to add unit test for this specific crash in order to prevent future regressions.