-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Incorrect percent encoding under Sonoma #4861
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
Comments
Analysis@xfoxfu Traced the change in behavior to an intentional change by Apple. From the Xcode 15 Release Notes:
Many thanks to @xfoxfu for identifying the cause of the change in behavior. Opening this URL in Firefox under macOS Ventura:
IINA correctly forms the URL:
That means this problem is a regression and is therefore a high priority to fix. Unfortunately… Opening this URL in Firefox under macOS Ventura:
FAILS reporting the URL can not be percent encoded:
There is a second, already existing, problem. Adding additional logging: Logger.log("Percent encoding \(str)")
guard let pstr = str.addingPercentEncoding(withAllowedCharacters: .urlAllowed) else {
Logger.log("Cannot add percent encoding for \(str)", level: .error, subsystem: subsystem)
return
}
Logger.log("Percent encoded \(pstr)")
guard let url = URL(string: pstr) else {
Logger.log("Cannot parse url for \(pstr)", level: .error, subsystem: subsystem)
return
} Shows the
The Why did IINA not report this same error running under Sonoma? Looking at the log message from the test under Sonoma shows
The URL initializer did not fail because it applied percent encoding to the guard let pstr = str.addingPercentEncoding(withAllowedCharacters: .urlAllowed), let url = URL(string: pstr) else { It uses extension CharacterSet {
static let urlAllowed: CharacterSet = {
var set = CharacterSet.urlHostAllowed
.union(.urlUserAllowed)
.union(.urlPasswordAllowed)
.union(.urlPathAllowed)
.union(.urlQueryAllowed)
.union(.urlFragmentAllowed)
set.insert(charactersIn: "%")
return set
}()
} Percent was added to the set a long time ago in commit 84927d7. The reason why CharacterSet provides the the different sets is that each URL component has different rules regarding what is allowed. It is concerning that IINA is trying to apply percent encoding to a full string. Posts on the net recommend using URLComponents which has always handled percent encoding. FixingCurrently PR #4860 removes the call to When built with Xcode 15 the proposed fix works:
But when built with Xcode 13 the new URL initializer behavior is not activated and the fix fails:
Full test output: Xcode 15, macOS Sonoma
Xcode 13, macOS Sonoma
The fix has to take into account the version of Xcode IINA was built with. Although the IINA README says:
IINA has plans to try and create one more release that supports macOS 10.11+. That requires building with Xcode 13. So it is currently undesirable to break compatibility with older versions of Xcode. Searching shows there are other places in the code where The next release of IINA is supposed to be a stabilizing release with a focus on fixing regressions. As the primary problem in this issue is a regression, that needs to be fixed. I'm thinking we should hold off fixing the other problem with failing to percent encode |
Thanks for your detailed test. I understand the next version is a stabilizing release, so the current pull request could be aligned with the current suggestion to avoid introducing new regressions. As a further followup, I am wondering why the URL needs to be precent-encoded, as it is observed that mpv supports URL with special characters.
Therefore, I would like to know if it is OK to assume that precent-encoding the URL is for making If so, I think it could be better to make precent-encoding as a fallback for func parseUrl(urlStr: String) -> URL? {
var urlComponents = URLComponents(string: urlStr)
if urlComponents == nil {
guard let pUrlStr = urlStr.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) else { return nil }
urlComponents = URLComponents(string: pUrlStr)
}
return urlComponents?.url
} and this logic could be shared between opening URL (1) from URL scheme and (2) from UI, which also addresses inconsistent behavior between these now on macOS Ventura. I have setup a GitHub repo with Actions to check the behavior between different macOS and XCode versions: https://github.com/xfoxfu/test-iina-swift-url. And the following test cases should be covere 8000 d:
I am not exactly sure about the encoding-decoding part, and some more time is required reading the RFC 3986 to provide precise test cases. I think this should be mostly reflecting the URL handling logic of mpv and browsers. |
I've created issue #4862 for the failure to handle |
* fix: avoid double percent-encode for url scheme Remove manual percent-encoding for URL opened in URL scheme. This will make URLs with special characters no longer be encoded twice and thus openable. See: https://developer.apple.com/documentation/foundation/url/3126806-init * fix: make URL parsing backward compatible with older macos Co-authored-by: low-batt <86170219+low-batt@users.noreply.github.com>
The fix for this issue has been merged into the IINA |
This was fixed in IINA 1.3.5. |
System and IINA version:
Expected behavior:
IINA correctly percent encodes URLs.
Actual behavior:
When running under macOS Sonoma IINA will perform percent encoding twice resulting in malformed URLs. @xfoxfu provided two examples:
Opening this URL in Firefox:
IINA changes
%5Bfoo%20bar.mkv
to be%5Bfoo%2520bar.mkv
:Opening this URL in Firefox:
IINA changes
%25foo%20bar.mkv
to be%25foo%2520bar.mkv
:This is a change from the behavior under macOS Ventura.
Steps to reproduce:
Enable logging in IINA
Open one of the URLs given above in Firefox
Look for the message shown above in IINA's log file
MPV does not have this problem.
This is an issue with IINA code. I have not checked if
mpv
also has this problem.How often does this happen?
Every time.
The text was updated successfully, but these errors were encountered: