summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Tollerton <rich.tollerton@ni.com>2019-01-10 15:41:08 -0600
committerRichard Tollerton <rich.tollerton@ni.com>2019-01-10 16:38:56 -0600
commit186966735dcccd61afde937118f27043bd084f57 (patch)
tree08fdd1766cf349dc519e32b87194de26b8b37237
parent74776910981b60877d25b1ab9587e5928af1e9c4 (diff)
xdg-open: handle file://localhost/
Presently, file://localhost/ URLs are totally unsupported: is_file_url_or_path correctly considers them files, but they are undecoded and hence check_input_file fails. While the standardization surrounding file: URLs is admittedly vague [1], AFAIK, *all* literature, and other implementations, unambiguously demonstrate that file://localhost/ should be equivalent to file:///: - The "File URI specification" explicitly linked to from the xdg-utils homepage [2] - RFC 8089 section 1.1 - RFC 1738 section 3.10 - Observed implementations of Windows `start`, macOS `open`, Firefox, Chrome, IE Fix this by adding some simple carve-outs for file://localhost specifically in file_url_to_path. [1] https://lists.freedesktop.org/archives/xdg/2004-November/003711.html [2] https://edeproject.org/spec/file-uri-spec.txt Signed-off-by: Richard Tollerton <rich.tollerton@ni.com>
-rwxr-xr-xautotests/t-xdg-open.sh6
-rw-r--r--scripts/xdg-open.in3
2 files changed, 8 insertions, 1 deletions
diff --git a/autotests/t-xdg-open.sh b/autotests/t-xdg-open.sh
index 810bdc3..0d4b8d2 100755
--- a/autotests/t-xdg-open.sh
+++ b/autotests/t-xdg-open.sh
@@ -155,3 +155,9 @@ test_generic_open_file 'test#file.txt'
test_that_it opens files with spaces in their name in generic mode
test_generic_open_file 'test file.txt'
+
+test_that_it opens file://localhost/ paths
+mock pcmanfm
+touch $LABDIR/file.txt
+run lxde xdg-open file://localhost$(pwd)/$LABDIR/file%2etxt
+assert_run pcmanfm $(pwd)/$LABDIR/file.txt
diff --git a/scripts/xdg-open.in b/scripts/xdg-open.in
index 4928538..09ef6d8 100644
--- a/scripts/xdg-open.in
+++ b/scripts/xdg-open.in
@@ -84,7 +84,8 @@ is_file_url_or_path()
file_url_to_path()
{
local file="$1"
- if echo "$file" | grep -q '^file:///'; then
+ if echo "$file" | grep -q '^file://\(localhost\)\?/'; then
+ file=${file#file://localhost}
file=${file#file://}
file=${file%%#*}
file=$(echo "$file" | sed -r 's/\?.*$//')