Skip to content

fix opening filenames with spaces on linux - #127

Merged
crazecoder merged 2 commits into
crazecoder:masterfrom
mx1up:filenames-with-spaces
Mar 9, 2021
Merged

fix opening filenames with spaces on linux#127
crazecoder merged 2 commits into
crazecoder:masterfrom
mx1up:filenames-with-spaces

Conversation

@mx1up

@mx1up mx1up commented Jan 31, 2021

Copy link
Copy Markdown
Contributor

fixes #126

I'm not sure about the other platforms, so I stayed out of it..

@miDeb

miDeb commented Feb 9, 2021

Copy link
Copy Markdown

Noticed this problem as well, but this is not actually enough since filenames can contain quotes as well! I solved this by appending a backslash in front of every character. (I wrote this in an email to the mantainer because I figured this might be a security vulnerability. It most likely isn't)

@miDeb

miDeb commented Feb 11, 2021

Copy link
Copy Markdown

I believe the best way to implement this is is to open the right process right away instead of using the system command: Process.start("$linuxDesktopName-open", [filePath]). That's how this rust crate works as well.

@mx1up

mx1up commented Feb 11, 2021

Copy link
Copy Markdown
Contributor Author

@miDeb you have a good point. TBH, I also don't understand why the system call is used here. I assumed the author had good reasons.. but maybe not as good as I hope ;) maybe @crazecoder can chime in.

I'll update my PR anyway to use Process

- xdg-open is available on all platforms, no need for other variations
- removed linux.dar: no longer needed
@crazecoder
crazecoder merged commit 315d0f3 into crazecoder:master Mar 9, 2021
@miDeb

miDeb commented Mar 9, 2021

Copy link
Copy Markdown

The same issue seems to exist on macOS fwiw.

miDeb added a commit to miDeb/open_file that referenced this pull request Jul 18, 2021
This removes the ability to use `system` to open files. Instead we use `Process.runSync`.

Quoting the [manpage for `system`](https://man.archlinux.org/man/system.3):
> Any user input that is employed as part of command should be carefully sanitized,
> to ensure that unexpected shell commands or command options are not executed.

AFAICT only spaces are replaced with `\ ` right now. This is not enough, and invoking the
`system` function is also completely unnecessary. Creating a new process directly is both
simpler and better. This option was introduced in crazecoder#127,
however only on linux and not as the default. This is not sufficient.

Running the following in an unsandboxed flutter app on linux would open `gnome-calculator`
(if installed, but you can place any command in there that will be executed):
```dart
  OpenFile.open(";gnome-calculator");
```

I haven't tested this on macOS but it _should_ work there similarly to linux.
miDeb added a commit to miDeb/open_file that referenced this pull request Sep 21, 2021
This removes the ability to use `system` to open files. Instead we use `Process.runSync`.

Quoting the [manpage for `system`](https://man.archlinux.org/man/system.3):
> Any user input that is employed as part of command should be carefully sanitized,
> to ensure that unexpected shell commands or command options are not executed.

AFAICT only spaces are replaced with `\ ` right now. This is not enough, and invoking the
`system` function is also completely unnecessary. Creating a new process directly is both
simpler and better. This option was introduced in crazecoder#127,
however only on linux and not as the default. This is not sufficient.

Running the following in an unsandboxed flutter app on linux would open `gnome-calculator`
(if installed, but you can place any command in there that will be executed):
```dart
  OpenFile.open(";gnome-calculator");
```

I haven't tested this on macOS but it _should_ work there similarly to linux.
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.

linux: opening filenames with spaces fails

3 participants