When trying to open the link to Who’s the Man from this article, I get the error messages shown below.
https://en.wikipedia.org/wiki/Party_and_Bullshit?wprov=sfti1
Version: WikipediaApp/6.9.3.1980 (iOS 16.1; Phone)
ARamadan-WMF | |
Oct 18 2022, 11:38 AM |
F35596396: unnamed (1).jpg | |
Oct 18 2022, 11:38 AM |
F35596397: unnamed.jpg | |
Oct 18 2022, 11:38 AM |
When trying to open the link to Who’s the Man from this article, I get the error messages shown below.
https://en.wikipedia.org/wiki/Party_and_Bullshit?wprov=sfti1
Version: WikipediaApp/6.9.3.1980 (iOS 16.1; Phone)
PR: https://github.com/wikimedia/wikipedia-ios/pull/4435 (CLOSED; replaced with new PR)
New PR: https://github.com/wikimedia/wikipedia-ios/pull/4444
The old PR was failing CircleCI tests, and the problem was that in iOS 15.5, URLComponents cannot be initialized with a string containing international (non-ASCII) characters. The tests still passed on my local computer because I was running them in iOS 16.2.
This PR fixes the existing code for encoding relative hrefs, and it does not hurt to do so, but I am not aware of any Wikipedia article links where we must percent-encode more than what is already encoded (except international characters). As mentioned above, encoding international characters in href before using it to initialize URLComponents is necessary, but after that, no further encoding is necessary to pass the URLParsingAndRoutingTests unit tests.
The code for encoding relative hrefs seems to have been originally added in this commit by @JoeWalsh in method ArticleViewController.handleLink (later moved to file URL+LinkParsing.swift, URL.resolvingRelativeWikiHref), but the reason for doing so isn't in the PR or commit messages.
Even if it isn't strictly necessary I think it's good practice to encode relative URLs just in case, but if there are cases where the further encoding is necessary, it would be helpful to add unit test cases for them.