Skip to content

Filepath with space not recognized correctly by xdg-open #17682

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

nickodei
Copy link
Contributor

@nickodei nickodei commented Dec 3, 2024

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 and 3.txt as additional parameters. This is obviously not the expected behaviour

What 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:

  • if xdg-open is installed on the os
  • and the file exist
var launcher = TopLevel.GetTopLevel(control).Launcher;
await launcher.LaunchFileInfoAsync(new FileInfo("/home/test/test 3.html")); 

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

  • How should I best test it? I tested it locally with different files like test 1.txt or "test 2".txt but I dont know if I should only test the escaping or how xdg-open can be mocked away

Fixed issues

Fixes #17301

@avaloniaui-bot
Copy link

You can test this PR using the following package version. 11.3.999-cibuild0053701-alpha. (feed url: https://nuget-feed-all.avaloniaui.net/v3/index.json) [PRBUILDID]

Copy link
Member

@maxkatz6 maxkatz6 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.
No, we don't have automated tests for Linux backend yet.

@maxkatz6 maxkatz6 enabled auto-merge December 3, 2024 21:53
@maxkatz6 maxkatz6 added this pull request to the merge queue Dec 3, 2024
Merged via the queue into AvaloniaUI:master with commit ab1d77a Dec 3, 2024
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Opening file with LaunchFileInfoAsync where path/filename contains space character
3 participants