alexisakers / HTMLString

Escape and unescape HTML entities in Swift
MIT License
170 stars 69 forks source link

Fix removeHTMLEntities may crash for NSString #23

Closed tomcheung closed 5 years ago

tomcheung commented 5 years ago

Refer to #22, use String.range to search & character with cause fatal error if that string is converted from NSString

This PR is going to fix this issue by using Substring and String.index to perform character searching, instead of using String.range

alexisakers commented 5 years ago

Thank you for your fix! Did you compare the performance of this approach to the previous one?

tomcheung commented 5 years ago

Here is the unit test report execute in my machine (iMac 5k 2017, Core i7 16 GB Ram, Xcode 10.2.1, Swift 5)

Seem this approach is surprisingly faster (compare result on testLargeUnescapingPerformance)

Previous

unit-test-report-before

Current

unit-test-report-after
alexisakers commented 5 years ago

Awesome! Thanks so much again. Will go into the next release 🚢