crazecoder / open_file

A plug-in that can call native APP to open files with string result in flutter, support iOS(UTI) / android(intent) / PC(ffi) / web(dart:html)
BSD 3-Clause "New" or "Revised" License
252 stars 438 forks source link

Error opening files with '(' character on Linux #150

Closed marcusgregory closed 3 years ago

marcusgregory commented 3 years ago

First I make an HTTP request and save the file to disk, here below is the response header with the filename:

flutter: /home/gregory/Documentos
flutter: x-powered-by: Servlet 2.5; JBoss-5.0/JBossWeb-2.1
x-powered-by: JSF/1.2
content-disposition: attachment; filename="DA LÍNGUA MATERNA À LÍNGUA SEGUNDA (2).pdf"
last-modified: Thu, 01 Jan 1970 00:00:00 GMT
date: Sun, 06 Jun 2021 17:10:01 GMT
transfer-encoding: chunked
content-type: application/pdf
server: Apache/2.4.6 (CentOS) mod_jk/1.2.42 OpenSSL/1.0.2k-fips

No exceptions occur at runtime, only show this message in the logs and the file doesn't open

sh: 1: Syntax error: "(" unexpected
mx1up commented 3 years ago

set linuxByProcess to true. then it uses xdg-open

marcusgregory commented 3 years ago

I sent a pull request fixing this issue, I think linuxByProcess is no longer needed, unless the developer explicitly wants to use it.

crazecoder commented 3 years ago

@mx1up I'm not familiar with Linux development, so is his solution appropriate

marcusgregory commented 3 years ago

Thanks for accepting the pull request, I assume I can close this issue now.

mx1up commented 3 years ago

@crazecoder I believe the issue is fixed by the addition of Uri.file, no need for string interpolation in system call or xdg-open arg I'll add a review to the PR

since linux.system call simply forks a new process with sh -c command, I'm not sure the shell supports the file uri's but I assume @marcusgregory has tested this

Also, this fix would make it no longer possible to open a remote file, i.e. https://abc.xyz/investor/static/pdf/2021Q1_alphabet_earnings_release.pdf but that's probably out of scope of this package :)

mx1up commented 3 years ago

@crazecoder sorry for the confusion, the linux.system call also simply calls xdg-open, so effectively, it is the same. I would vote to remove one code path. Both spawn a process, using the linux.system call, you spawn an extra process (the shell process) and it does not add any benefit. So I would simply call Process.run as it is the most transparent and efficient.

actually, according to the documentation, system call seems to spawn 2 extra processes: https://man7.org/linux/man-pages/man3/system.3.html