unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Danny Freeman via "Bug reports for GNU Emacs, the Swiss army knife of text editors" <bug-gnu-emacs@gnu.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: 58790@debbugs.gnu.org, dgutov@yandex.ru,
	felician.nemeth@gmail.com, "João Távora" <joaotavora@gmail.com>,
	stefankangas@gmail.com
Subject: bug#58790: Eglot URI parsing bug when using clojure-lsp server
Date: Thu, 10 Nov 2022 16:45:27 -0500	[thread overview]
Message-ID: <87k042tqze.fsf@dfreeman.email> (raw)
In-Reply-To: <83o7terf9a.fsf@gnu.org>

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


Eli Zaretskii <eliz@gnu.org> writes:

>
> OK, then I have a few minor comments, before this can be installed:
>
> This lacks ChangeLog-style parts which specify the file(s) and
> function(s) which were changed.

Thanks for your patience, I believe I've got that corrected now. See the
attachments.

> Also, in the text above, please leave two spaces between sentences,
> per our conventions, and refill the text to be at most 63 columns.

I cut it down to 63. I don't mind either way, but thought I would
mention that the CONTRIBUTE file mentions 79 columns, which is what I
normally default to in commit messages.

>> The file-name-operation being checked, any-handler, has no significant
>> meaning, other than that it is not one that would be suppressed by
>> inhibit-file-name-operation. We just want to check that a handler exists
>> and has the potential to handle this URI, not actually dispatch a
>> file-name-operation right now.
>
> Same here.  And in this case, the text should definitely be in
> comments.

Done!!!


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: Only parse file: URIs --]
[-- Type: text/x-patch, Size: 3849 bytes --]

From a5b1b6b34d3d455e06757bbb1c10df8f81121f1f Mon Sep 17 00:00:00 2001
From: dannyfreeman <danny@dfreeman.email>
Date: Thu, 3 Nov 2022 09:39:16 -0400
Subject: [PATCH] Eglot: Only handle URIs with the file:// scheme

This fixes Bug#58790

* lisp/progmodes/eglot.el (eglot--path-to-uri, eglot--uri-to-path):
This issue originated with clojure-lsp sending clients "jar"
type URIs that Emacs is unable to handle out of the box.  Before
this change, jar: URIs were parsed once, but since jar: URIs
contain a nested URI, this resulted in a file being dispatched
with a partially parsed path that looked like
`file://path/to.jar!/path/in/jar`.  Now eglot will not attempt
to parse them at all.
---
 lisp/progmodes/eglot.el | 46 ++++++++++++++++++++++++++---------------
 1 file changed, 29 insertions(+), 17 deletions(-)

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index b707a6b059..11bf0884ac 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -1500,29 +1500,41 @@ eglot--uri-path-allowed-chars
 (defun eglot--path-to-uri (path)
   "URIfy PATH."
   (let ((truepath (file-truename path)))
-    (concat "file://"
-            ;; Add a leading "/" for local MS Windows-style paths.
-            (if (and (eq system-type 'windows-nt)
-                     (not (file-remote-p truepath)))
-                "/")
-            (url-hexify-string
-             ;; Again watch out for trampy paths.
-             (directory-file-name (file-local-name truepath))
-             eglot--uri-path-allowed-chars))))
+    (if (url-type (url-generic-parse-url truepath))
+        ;; Path is already a URI, so forward it to the lsp server untouched.
+        ;; This assumes that the server can handle the same non-file
+        ;; scheme URIs that it provides to clients.
+        truepath
+      (concat "file://"
+              ;; Add a leading "/" for local MS Windows-style paths.
+              (if (and (eq system-type 'windows-nt)
+                       (not (file-remote-p truepath)))
+                  "/")
+              (url-hexify-string
+               ;; Again watch out for trampy paths.
+               (directory-file-name (file-local-name truepath))
+               eglot--uri-path-allowed-chars)))))
 
 (defun eglot--uri-to-path (uri)
   "Convert URI to file path, helped by `eglot--current-server'."
   (when (keywordp uri) (setq uri (substring (symbol-name uri) 1)))
   (let* ((server (eglot-current-server))
          (remote-prefix (and server (eglot--trampish-p server)))
-         (retval (url-unhex-string (url-filename (url-generic-parse-url uri))))
-         ;; Remove the leading "/" for local MS Windows-style paths.
-         (normalized (if (and (not remote-prefix)
-                              (eq system-type 'windows-nt)
-                              (cl-plusp (length retval)))
-                         (substring retval 1)
-                       retval)))
-    (concat remote-prefix normalized)))
+         (url (url-generic-parse-url uri)))
+    ;; Only attempt to parse URIs with the file scheme.
+    (if (string= "file" (url-type url))
+        (let* ((retval (url-unhex-string (url-filename url)))
+               ;; Remove the leading "/" for local MS Windows-style paths.
+               (normalized (if (and (not remote-prefix)
+                                    (eq system-type 'windows-nt)
+                                    (cl-plusp (length retval)))
+                               (substring retval 1)
+                             retval)))
+          (concat remote-prefix normalized))
+      ;; Leave non-file scheme URIs untouched.
+      ;; Handlers registered with `file-name-handler-alist' can
+      ;; identify these URIs and decide how to handle them.
+      uri)))
 
 (defun eglot--snippet-expansion-fn ()
   "Compute a function to expand snippets.
-- 
2.38.1


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: Warn when unhandled file: URI is received --]
[-- Type: text/x-patch, Size: 1440 bytes --]

From 7fd1e7c4a264d74360d79c6cbee3f0e0aceeab5c Mon Sep 17 00:00:00 2001
From: dannyfreeman <danny@dfreeman.email>
Date: Thu, 10 Nov 2022 13:05:49 -0500
Subject: [PATCH] Eglot: warn when receiving a non-file scheme URI

Addresses bug#58790

* lisp/progmodes/eglot.el (eglot--uri-to-path): Write a message
when eglot encounters a non-file scheme URI that Emacs is not
capable of handling.
---
 lisp/progmodes/eglot.el | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el
index 11bf0884ac..dfa18b885f 100644
--- a/lisp/progmodes/eglot.el
+++ b/lisp/progmodes/eglot.el
@@ -1531,6 +1531,13 @@ eglot--uri-to-path
                                (substring retval 1)
                              retval)))
           (concat remote-prefix normalized))
+      ;; `any-handler', has no significant meaning, other than that it
+      ;; is not one that would be suppressed by `inhibit-file-name-operation'.
+      ;; We just want to check that a handler exists and has the potential
+      ;; to handle this URI, not actually dispatch a
+      ;; file-name-operation right now.
+      (unless (find-file-name-handler uri 'any-handler)
+        (eglot--message "Received URI with unexpected scheme: %s" uri))
       ;; Leave non-file scheme URIs untouched.
       ;; Handlers registered with `file-name-handler-alist' can
       ;; identify these URIs and decide how to handle them.
-- 
2.38.1


[-- Attachment #4: Type: text/plain, Size: 31 bytes --]



Thank you,
-- 
Danny Freeman

  reply	other threads:[~2022-11-10 21:45 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-10-25 21:44 bug#58790: Eglot URI parsing bug when using clojure-lsp server Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-26  6:22 ` Stefan Kangas
2022-10-26 19:50   ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-27 15:09     ` João Távora
2022-10-29  1:22       ` Dmitry Gutov
2022-10-29  2:02         ` João Távora
2022-10-29 14:54           ` Dmitry Gutov
2022-10-29 19:35             ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-10-31 14:40               ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-02  8:09                 ` João Távora
2022-11-02 13:15                   ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-03 17:10                   ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-10  9:49                     ` Eli Zaretskii
2022-11-10 11:00                       ` João Távora
2022-11-10 13:47                         ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-10 15:38                         ` Eli Zaretskii
2022-11-10 21:45                           ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors [this message]
2022-11-10 21:59                             ` João Távora
2022-11-10 22:22                               ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-10 22:30                                 ` João Távora
2022-11-10 22:48                                   ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-10 22:48                                 ` João Távora
2022-11-10 22:57                                   ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-11  7:29                                   ` Eli Zaretskii
2022-11-12 17:03                                     ` Michael Albinus
2022-11-13 21:04                                       ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-15 19:04                                         ` Michael Albinus
2022-11-15 22:28                                           ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-16  7:53                                             ` Michael Albinus
2022-11-16 10:21                                               ` João Távora
2022-11-16 15:45                                                 ` Michael Albinus
2022-11-16 16:20                                                   ` João Távora
2022-11-16 22:59                                                     ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-02 16:14                                                       ` Michael Albinus
2022-12-07 18:56                                                         ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-08 13:46                                                           ` Michael Albinus
2022-12-08 19:07                                                             ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-09 16:04                                                               ` Michael Albinus
2022-12-10 17:21                                                                 ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-12-10 17:45                                                                   ` Michael Albinus
2022-11-22 14:30                                                     ` Michael Albinus
2022-11-23 11:55                                                       ` Richard Copley
2022-11-23 12:36                                                         ` João Távora
2022-11-23 12:42                                                           ` Arash Esbati
2022-11-23 12:49                                                             ` Richard Copley
2022-11-23 12:54                                                               ` João Távora
2022-11-23 13:33                                                           ` Eli Zaretskii
2022-11-23 13:44                                                             ` João Távora
2022-11-23 14:03                                                               ` Danny Freeman via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-11-23 19:53                                                                 ` João Távora
2022-11-11  8:30                               ` Eli Zaretskii
2022-11-11  9:45                                 ` João Távora
2022-11-11 12:01                                   ` Eli Zaretskii
2022-11-11 14:02                                     ` João Távora
2022-11-11 14:45                                       ` Eli Zaretskii
2022-11-12  9:04                                         ` João Távora
2022-11-11  7:16                             ` Eli Zaretskii
2022-11-01 17:25         ` Juri Linkov
2022-10-29 15:36 ` Felician Nemeth
2022-10-29 17:09   ` João Távora
2022-11-09  0:59 ` bug#58790: Robert Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87k042tqze.fsf@dfreeman.email \
    --to=bug-gnu-emacs@gnu.org \
    --cc=58790@debbugs.gnu.org \
    --cc=danny@dfreeman.email \
    --cc=dgutov@yandex.ru \
    --cc=eliz@gnu.org \
    --cc=felician.nemeth@gmail.com \
    --cc=joaotavora@gmail.com \
    --cc=stefankangas@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).