Filepath with space not recognized correctly by xdg-open #17682
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What does the pull request do?
This implementation wraps the file path given to
xdg-open
with quotation-marks and escapes the quotation-marks correctly. This affects only programs running on Linux.What is the current behavior?
As mentioned in #17301, when you open a file path that contains a space in it e.g
/home/test/test 3.txt
it will take the first part/home/test/test
as the file path and3.txt
as additional parameters. This is obviously not the expected behaviourWhat is the updated/expected behavior with this PR?
The correct and escaped file path should be parsed to
xdg-open
so the file is opened.Example:
When running the following code, it should open the file in the browser:
How was the solution implemented (if it's not obvious)?
When wrapping the file path in quotation marks like that:
xdg-open "/home/test/test 3.html"
, it will work correctly. The problem is that we escape the whole command so we can send it to/bin/sh -c \"{command}\"
and the upper command will be translated to:/bin/sh -c "xdg-open \\\"/home/test/test 3.html\\\""
which is unfortunately not correct. The outer quotation marks should only translate to:/bin/sh -c "xdg-open \"/home/test/test 3.html\""
but the inner paths should still be (e.g with file"test 3".txt
):/bin/sh -c "xdg-open \"/home/test/\\\"test 3\\\".html\""
.This is done by escaping the file path as before but only escaping the quotation marks wrapping the file path with
\"
.Checklist
Questions
test 1.txt
or"test 2".txt
but I dont know if I should only test the escaping or howxdg-open
can be mocked awayFixed issues
Fixes #17301