cordova-plugin-file
cordova-plugin-file copied to clipboard
feat(ios): replace deprecated properties
Platforms affected
iOS
Motivation and Context
#631
Description
Replace deprecated properties
Testing
Expect GitHub Actions test suite to pass as before
Checklist
- [x] I've run the tests to see all new and existing tests pass
- [x] I added automated test coverage as appropriate for this change
- [x] Commit is prefixed with
(platform)if this change only applies to one platform (e.g.(android)) - [x] If this Pull Request resolves an issue, I linked to the issue in the text above (and used the correct keyword to close issues using keywords)
- [x] I've updated the documentation if necessary
stringByRemovingPercentEncoding and stringByAddingPercentEncodingWithAllowedCharacters are both iOS 7+ so compatibility wise it should be fine.
The newer APIs gives a warning...
stringByRemovingPercentEncoding:
You must call this method only on strings that you know to be percent-encoded. Calling this method on strings that are not percent-encoded can lead to misinterpreting a percent character as the beginning of a percent-encoded sequence.
stringByAddingPercentEncodingWithAllowedCharacters:
You must not call this method on strings that are already percent-encoded. Calling this method on strings that are already percent-encoded will cause percent characters in a percent-encoded sequence to be percent-encoded twice.
I'm not sure how the older deprecated APIs behave but the encodePath API path has comments suggesting it doesn't know if the given url is already encoded or not (by blindly decoding it and re-encoding it). Depending how the deprecated API behaves, switching out the APIs might not be sufficient.
stringByAddingPercentEncodingWithAllowedCharacters has a similar warning that encoding an already encoded url will result in double encoding.
Also stringByAddingPercentEncodingWithAllowedCharacters is being used wrong, as it doesn't accept character encoding, but a NSCharacterSet instead defining allowed characters. So that's failing the build.
Thanks for the detailed review. I'll let you decide if it's worth pursuing these changes, especially as it's not a like-for-like replacement in either case. My aim was to reduce the amount of noise I was seeing in my log as deprecation warnings.