Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deprecation warning for iOS/tvOS: stringByAddingPercentEscapesUsingEncoding: #44

Open
Coeur opened this issue Mar 29, 2016 · 3 comments

Comments

@Coeur
Copy link
Collaborator

Coeur commented Mar 29, 2016

- WARN  | [tvOS] xcodebuild:  TSMarkdownParser/TSMarkdownParser/TSMarkdownParser.m:253:77: warning: 'stringByAddingPercentEscapesUsingEncoding:' is deprecated: first deprecated in tvOS 9.0 - Use -stringByAddingPercentEncodingWithAllowedCharacters: instead, which always uses the recommended UTF-8 encoding, and which encodes for a specific URL component or subcomponent since each URL component or subcomponent has different rules for what characters are valid. [-Wdeprecated-declarations]

But because we are trying to do some error handling here, we would need to manually decompose the string to be aware of the components of the URL to percent-escape.

@Coeur Coeur changed the title deprecation warning for tvOS 9.0 deprecation warning for tvOS 9.0: stringByAddingPercentEscapesUsingEncoding: Mar 29, 2016
@Coeur
Copy link
Collaborator Author

Coeur commented Apr 30, 2016

If someone wants to help, the goal is to recode stringByAddingPercentEscapesUsingEncoding: to work on a string which isn't recognized by URLWithString:

@uaremad
Copy link

uaremad commented Apr 5, 2017

Replace
NSURL* url = [NSURL URLWithString:link] ?: [NSURL URLWithString: [link stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

With
NSCharacterSet *set = [NSCharacterSet URLHostAllowedCharacterSet];
NSURL *url = [NSURL URLWithString:link] ?: [NSURL URLWithString: [link stringByAddingPercentEncodingWithAllowedCharacters:set]];

@Coeur Coeur self-assigned this Jun 29, 2017
@Coeur
Copy link
Collaborator Author

Coeur commented Mar 27, 2018

@uaremad, thank you, but it's a bit more complex: URL is multi parts (host / path ? query # anchor), so it needs various escapes. And default Apple character sets aren't even RFC compliant, so we have to consider extra workarounds like done by https://github.com/Alamofire/Alamofire/blob/ab07523ee93527e79e99037f1a2d596b30689016/Source/ParameterEncoding.swift#L196

@Coeur Coeur changed the title deprecation warning for tvOS 9.0: stringByAddingPercentEscapesUsingEncoding: deprecation warning for iOS/tvOS: stringByAddingPercentEscapesUsingEncoding: Mar 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants