TSMarkdownParser icon indicating copy to clipboard operation
TSMarkdownParser copied to clipboard

deprecation warning for iOS/tvOS: `stringByAddingPercentEscapesUsingEncoding:`

Open Coeur opened this issue 10 years ago • 3 comments

- 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 avatar Mar 29 '16 07:03 Coeur

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

Coeur avatar Apr 30 '16 08:04 Coeur

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]];

uaremad avatar Apr 05 '17 21:04 uaremad

@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 avatar Mar 27 '18 06:03 Coeur