-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
fix: avoid double percent-encode for url scheme #4860
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
Conversation
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
How do I reproduce the problem this PR fixes? Running under macOS 14.4 I opened the following URL in Firefox:
And I'm not seeing double percent encoding in IINA's log:
|
Interesting, it seems only having whitespaces in the URL is not sufficient to trigger the bug. Please try this URL: iina://weblink?url=https://example/%25foo%20bar.mkv 03:47:28.786 [iina][d] URL event: iina://weblink?url=https://example/%25foo%20bar.mkv
03:47:28.786 [iina][d] Parsing URL iina://weblink?url=https://example/%25foo%20bar.mkv
03:47:28.786 [player0][d] Open URL: https://example/%25foo%2520bar.mkv
03:47:28.786 [player0][d] Opening https://example/%25foo%2520bar.mkv in main window And this one: iina://weblink?url=https://example/%5Bfoo%20bar.mkv 03:49:51.240 [iina][d] URL event: iina://weblink?url=https://example/%5Bfoo%20bar.mkv
03:49:51.240 [iina][d] Parsing URL iina://weblink?url=https://example/%5Bfoo%20bar.mkv
03:49:51.240 [player0][d] Open URL: https://example/%5Bfoo%2520bar.mkv
03:49:51.240 [player0][d] Opening https://example/%5Bfoo%2520bar.mkv in main window |
Thanks for the update. Reproduced for me now. Very busy today. I will be taking a close look into this problem. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent work tracking this problem to Apple's change. I really appreciate your investigation and proposed fix.
The call to addingPercentEncoding
can't be fully removed because the new behavior is only present when running under macOS Sonoma and only if built with Xcode 15. Look for the suggested change.
I've created issue #4861 for this problem. See that issue for a full discussion. There are other places in the code that probably need to be updated. We'd want to be able to reproduce a problem before making changes.
Co-authored-by: low-batt <86170219+low-batt@users.noreply.github.com>
Thanks for your suggestions, and I have tested on macOS Ventura with XCode 15.2 that the problem has been resolved, but I do not have access to older macOS or XCode. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tested this PR on two machines:
- MacOS Sonoma w/ Xcode 15.2
- MacOS Monterey w/ Xcode 13.4.1
IINA used for testing was compiled locally on the corresponding machine. The #if compiler(>=5.9)
check works as intended. And confirmed the proposed fix doesn't break when IINA is built by older version Xcode.
However, during testing, I found that this URL: iina://weblink?url=https://example/%25foo%20bar.mkv
cannot be parsed on the older machine. Because we allowed .urlAllowed
, which is customized in here:
This is where we manually added "%" into the CharSet, so that the pstr
becomes https://example/%foo%20bar.mkv
after addingPercentEncoding
and thus invalid for further parsing. Not sure why we manually added "%" before.
This is not caused by this PR, so this one is safe to merge.
Actually, I think allowing A better way of handling these "endless" corner cases easily could be utilizing the new |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pulled the latest commits and tested under Ventura and Sonoma.
Changes look good to me.
Description:
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.
Due to a recent change in Apple
URL.init
, URL will be encoded automatically, see: https://developer.apple.com/documentation/foundation/url/3126806-initTherefore, if the URL is percent-encoded beforehand, it will be encoded a second time if
URL
is constructed.This PR removes the first manual percent-encoding, which makes URL correct.