unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#55357: 29.0.50; [PATCH] Fix browse-url-emacs on file:// urls
@ 2022-05-11  7:05 Yuan Fu
  2022-05-11  7:53 ` Andreas Schwab
  2022-05-11 11:37 ` Eli Zaretskii
  0 siblings, 2 replies; 5+ messages in thread
From: Yuan Fu @ 2022-05-11  7:05 UTC (permalink / raw)
  To: 55357

[-- Attachment #1: Type: text/plain, Size: 411 bytes --]


If you call browse-url-emacs with a file:// url, Emacs does not open the correct file:

(browse-url-emacs "file://~/a/b") opens /a/b
(browse-url-emacs "file://a/b") opens /b

Basically unless the path is an absolute path, the first level is chopped because url parses it as host and throws it away. This patch concats the host back. If the path is absolute, host is empty string so it’s ok.

Yuan


[-- Attachment #2: file-url.patch --]
[-- Type: application/octet-stream, Size: 714 bytes --]

diff --git a/lisp/net/browse-url.el b/lisp/net/browse-url.el
index 66898d7707..393ed76e8b 100644
--- a/lisp/net/browse-url.el
+++ b/lisp/net/browse-url.el
@@ -1250,7 +1250,9 @@ browse-url-emacs
         (func (if same-window 'find-file 'find-file-other-window)))
     (if (equal (url-type parsed) "file")
         ;; It's a file; just open it.
-        (let ((file (url-unhex-string (url-filename parsed))))
+        (let ((file (url-unhex-string
+                     (concat (url-host parsed)
+                             (url-filename parsed)))))
           (when-let ((coding (browse-url--file-name-coding-system)))
             (setq file (decode-coding-string file 'utf-8)))
           (funcall func file))

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* bug#55357: 29.0.50; [PATCH] Fix browse-url-emacs on file:// urls
  2022-05-11  7:05 bug#55357: 29.0.50; [PATCH] Fix browse-url-emacs on file:// urls Yuan Fu
@ 2022-05-11  7:53 ` Andreas Schwab
  2022-05-11 11:37 ` Eli Zaretskii
  1 sibling, 0 replies; 5+ messages in thread
From: Andreas Schwab @ 2022-05-11  7:53 UTC (permalink / raw)
  To: Yuan Fu; +Cc: 55357

On Mai 11 2022, Yuan Fu wrote:

> (browse-url-emacs "file://~/a/b") opens /a/b
> (browse-url-emacs "file://a/b") opens /b

That is correct.  The component after file:// is always the host part.
See RFC8089 for the full specification.

> Basically unless the path is an absolute path, the first level is chopped because url parses it as host and throws it away. This patch concats the host back. If the path is absolute, host is empty string so it’s ok.

The host part can be non-empty, too.

-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510  2552 DF73 E780 A9DA AEC1
"And now for something completely different."





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#55357: 29.0.50; [PATCH] Fix browse-url-emacs on file:// urls
  2022-05-11  7:05 bug#55357: 29.0.50; [PATCH] Fix browse-url-emacs on file:// urls Yuan Fu
  2022-05-11  7:53 ` Andreas Schwab
@ 2022-05-11 11:37 ` Eli Zaretskii
  2022-05-11 18:35   ` Yuan Fu
  1 sibling, 1 reply; 5+ messages in thread
From: Eli Zaretskii @ 2022-05-11 11:37 UTC (permalink / raw)
  To: Yuan Fu; +Cc: 55357

> Resent-From: Yuan Fu <casouri@gmail.com>
> Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
> Resent-CC: bug-gnu-emacs@gnu.org
> Resent-Sender: help-debbugs@gnu.org
> From: Yuan Fu <casouri@gmail.com>
> Date: Wed, 11 May 2022 00:05:50 -0700
> 
> 
> [1:text/plain Hide]
> 
> 
> If you call browse-url-emacs with a file:// url, Emacs does not open the correct file:
> 
> (browse-url-emacs "file://~/a/b") opens /a/b
> (browse-url-emacs "file://a/b") opens /b
> 
> Basically unless the path is an absolute path, the first level is chopped because url parses it as host and throws it away. This patch concats the host back. If the path is absolute, host is empty string so it’s ok.

I think your URLs lack one or two more slashes.  See

  https://en.wikipedia.org/wiki/File_URI_scheme#How_many_slashes?





^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#55357: 29.0.50; [PATCH] Fix browse-url-emacs on file:// urls
  2022-05-11 11:37 ` Eli Zaretskii
@ 2022-05-11 18:35   ` Yuan Fu
  2022-05-11 18:35     ` Yuan Fu
  0 siblings, 1 reply; 5+ messages in thread
From: Yuan Fu @ 2022-05-11 18:35 UTC (permalink / raw)
  To: Eli Zaretskii; +Cc: 55357



> On May 11, 2022, at 4:37 AM, Eli Zaretskii <eliz@gnu.org> wrote:
> 
>> Resent-From: Yuan Fu <casouri@gmail.com>
>> Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
>> Resent-CC: bug-gnu-emacs@gnu.org
>> Resent-Sender: help-debbugs@gnu.org
>> From: Yuan Fu <casouri@gmail.com>
>> Date: Wed, 11 May 2022 00:05:50 -0700
>> 
>> 
>> [1:text/plain Hide]
>> 
>> 
>> If you call browse-url-emacs with a file:// url, Emacs does not open the correct file:
>> 
>> (browse-url-emacs "file://~/a/b") opens /a/b
>> (browse-url-emacs "file://a/b") opens /b
>> 
>> Basically unless the path is an absolute path, the first level is chopped because url parses it as host and throws it away. This patch concats the host back. If the path is absolute, host is empty string so it’s ok.
> 
> I think your URLs lack one or two more slashes. See
> 
> https://en.wikipedia.org/wiki/File_URI_scheme#How_many_slashes?

Ah! My bad. Closing.

Yuan






^ permalink raw reply	[flat|nested] 5+ messages in thread

* bug#55357: 29.0.50; [PATCH] Fix browse-url-emacs on file:// urls
  2022-05-11 18:35   ` Yuan Fu
@ 2022-05-11 18:35     ` Yuan Fu
  0 siblings, 0 replies; 5+ messages in thread
From: Yuan Fu @ 2022-05-11 18:35 UTC (permalink / raw)
  To: 55357-done



> On May 11, 2022, at 11:35 AM, Yuan Fu <casouri@gmail.com> wrote:
> 
> 
> 
>> On May 11, 2022, at 4:37 AM, Eli Zaretskii <eliz@gnu.org> wrote:
>> 
>>> Resent-From: Yuan Fu <casouri@gmail.com>
>>> Original-Sender: "Debbugs-submit" <debbugs-submit-bounces@debbugs.gnu.org>
>>> Resent-CC: bug-gnu-emacs@gnu.org
>>> Resent-Sender: help-debbugs@gnu.org
>>> From: Yuan Fu <casouri@gmail.com>
>>> Date: Wed, 11 May 2022 00:05:50 -0700
>>> 
>>> 
>>> [1:text/plain Hide]
>>> 
>>> 
>>> If you call browse-url-emacs with a file:// url, Emacs does not open the correct file:
>>> 
>>> (browse-url-emacs "file://~/a/b") opens /a/b
>>> (browse-url-emacs "file://a/b") opens /b
>>> 
>>> Basically unless the path is an absolute path, the first level is chopped because url parses it as host and throws it away. This patch concats the host back. If the path is absolute, host is empty string so it’s ok.
>> 
>> I think your URLs lack one or two more slashes. See
>> 
>> https://en.wikipedia.org/wiki/File_URI_scheme#How_many_slashes?
> 
> Ah! My bad. Closing.
> 
> Yuan
> 






^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-05-11 18:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-11  7:05 bug#55357: 29.0.50; [PATCH] Fix browse-url-emacs on file:// urls Yuan Fu
2022-05-11  7:53 ` Andreas Schwab
2022-05-11 11:37 ` Eli Zaretskii
2022-05-11 18:35   ` Yuan Fu
2022-05-11 18:35     ` Yuan Fu

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).