Skip to content

Fix mvim:// protocol handler not working well with iTerm2 #1043

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

Merged

Conversation

ychin
Copy link
Member

@ychin ychin commented Apr 20, 2020

iTerm2's MacVim integration generates URLs that has the file separator ("/") escaped as ("%2F"). This is incorrect (as it implies the slash is part of the file name itself instead of a separator), but work around it for now. Instead of using NSURL to parse the file:// URL, just decode the input parameter and manually parse it. This still handles the special characters like space or "?", but will handle the escaped slashes as well. Given that "/" is not a valid filename character we should not run into ambiguity here.

Also, add dialog boxes to show an error if MacVim doesn't know how to handle a file path.

Will add regression tests for these edge cases in a future commit.

Fix #1020

iTerm2's MacVim integration generates URLs that has the file separator
("/") escaped as ("%2F"). This is incorrect (as it implies the slash is
part of the file name itself instead of a separator), but work around it
for now. Instead of using NSURL to parse the file:// URL, just decode
the input parameter and manually parse it. This still handles the
special characters like space or "?", but will handle the escaped
slashes as well. Given that "/" is not a valid filename character we
should not run into ambiguity here.

Also, add dialog boxes to show an error if MacVim doesn't know how to
handle a file path.

Will add regression tests for these edge cases in a future commit.

Fix macvim-dev#1020
@ychin ychin added this to the snapshot-164 milestone Apr 20, 2020
@ychin ychin merged commit 6fe1997 into macvim-dev:master Apr 20, 2020
@ychin ychin deleted the mvim-protocol-handler-iterm-escape-fix branch April 20, 2020 05:17
ychin added a commit to ychin/macvim that referenced this pull request Jul 6, 2020
Change mvim:// protocol behavior back to previous state to double-encode
the file path, since we are encapsulating a file:// protocol (which has
encoded path) within another URL as a query, which itself should be
encoded. This means a file path "/tmp/file name.txt" should be properly
encoded as mvim://open?url=file:///tmp/file%2520name.txt, as the space
is encoded twice (first to %20, then to %2520).

Previously we tried to fix the protocol handler to only do a single
encoding (see macvim-dev#1021 and macvim-dev#1043) but it's really an incorrect usage of
URL. The reason for that fix was that tools like iTerm2 was passing in
single-encoded URLs. As such, also add a compatibility feature here
where we will optimiscally try to re-encode characters that we detect to
be erroneously encoded. For example, if we see
mvim://open?url=file:///tmp/file%20name.txt, MacVim will intelligently
realize that the space needs to be encoded again. The only character
where that won't work is the "%" character because of the ambiguity
involved, so a file path "/tmp/file%.txt" will only work with this:
mvim://open?url=file:///tmp/file%2525.txt

Close macvim-dev#1020 (also see the issue for discussions).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

macvim url scheme with line number is broken
1 participant