From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Danny Freeman via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#58790: Eglot URI parsing bug when using clojure-lsp server Date: Thu, 10 Nov 2022 17:22:15 -0500 Message-ID: <87fseqtpiu.fsf@dfreeman.email> References: <8cf8ba5d-c604-b2dc-274a-7597b19fb73f@dfreeman.email> <87ilk5xq01.fsf@gmail.com> <87r0yrwfn3.fsf@gmail.com> <37716e41-5955-99f6-5204-e760a716fbf6@yandex.ru> <9bb290c8-f000-31d8-265d-b5441c33eb38@dfreeman.email> <4d50b820-7053-75eb-5b11-d3d36a02b013@dfreeman.email> <87v8nxsrq6.fsf@gmail.com> <87cza40xgs.fsf@dfreeman.email> <83edubrvf0.fsf@gnu.org> <87cz9v9irh.fsf@gmail.com> <83o7terf9a.fsf@gnu.org> <87k042tqze.fsf@dfreeman.email> Reply-To: Danny Freeman Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="28460"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Eli Zaretskii , dgutov@yandex.ru, felician.nemeth@gmail.com, 58790@debbugs.gnu.org, stefankangas@gmail.com To: =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Nov 10 23:27:22 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1otG13-00077f-Sy for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 10 Nov 2022 23:27:22 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1otG0m-00076L-78; Thu, 10 Nov 2022 17:27:04 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1otG0k-000762-KM for bug-gnu-emacs@gnu.org; Thu, 10 Nov 2022 17:27:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1otG0k-0001uE-CD for bug-gnu-emacs@gnu.org; Thu, 10 Nov 2022 17:27:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1otG0j-0005im-VF for bug-gnu-emacs@gnu.org; Thu, 10 Nov 2022 17:27:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Danny Freeman Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 10 Nov 2022 22:27:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 58790 X-GNU-PR-Package: emacs Original-Received: via spool by 58790-submit@debbugs.gnu.org id=B58790.166811918821951 (code B ref 58790); Thu, 10 Nov 2022 22:27:01 +0000 Original-Received: (at 58790) by debbugs.gnu.org; 10 Nov 2022 22:26:28 +0000 Original-Received: from localhost ([127.0.0.1]:44577 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1otG0B-0005hy-KB for submit@debbugs.gnu.org; Thu, 10 Nov 2022 17:26:28 -0500 Original-Received: from out0.migadu.com ([94.23.1.103]:41115) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1otG07-0005hm-AI for 58790@debbugs.gnu.org; Thu, 10 Nov 2022 17:26:25 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dfreeman.email; s=key1; t=1668119181; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=MYiAxnbvk87jUR89SkSZrd5Kid/WQuD0f0VVmxR5GZ8=; b=u3xMemzp0sbTDsyEdCIadr8sE8sw+KEymwhLoyaJe+wDSrgsm5YS7wGh5uJqmOm0GaoIsn RhXt7Mrxax11X8ARpP6xM0cT4baGg2NwwhtNvHAC0gdsAazBAbbxP3srs3tsSU96ChFWrA 9C2acre1C09QiickYaD/qL+GFwh2ci4= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. In-reply-to: X-Migadu-Flow: FLOW_OUT X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:247556 Archived-At: --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Jo=C3=A3o T=C3=A1vora writes: > I agree on the two comments about the ChangeLog style entries and the > spacing.=20=20 > > But when dealing with eglot.el, which I am the prime maintainer of,=20 > I really prefer to see design described in the commit message where the=20 > design was introduced. It plays very well with vc-region-history. > > So Danny, if you don't mind, please revert that part.=20=20 > > Jo=C3=A3o Yall all really taking me for a ride on this lol. In reviewing the comments over and over I've made a modification to the second patch involving the warning message. Instead of using an arbitrary symbol I realized that the function `find-file-name-handler' works when a nil value for the second argument (operation). Anyways, here they are again. --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Eglot-Only-handle-URIs-with-the-file-scheme.patch >From e56e987cbf601f6caffac7edfdd580a0b7da921f Mon Sep 17 00:00:00 2001 From: dannyfreeman Date: Thu, 3 Nov 2022 09:39:16 -0400 Subject: [PATCH 1/2] Eglot: Only handle URIs with the file:// scheme This fixes Bug#58790 * lisp/progmodes/eglot.el (eglot--path-to-uri, eglot--uri-to-path): Eglot will not attempt to parse URIs that are not file:// type at all, instead let `file-name-handler-alist' entries to deal with them. Not parsing them at all allows the `file-name-handler-alist' regexps to identify them more accurately. By also checking if eglot received a URI in `eglot--path-to-uri', the `file-name-handler-alist' can provide the non-file type URI back to the lsp server, which presumably will know how to handle them since it is also giving them out to clients. 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". --- lisp/progmodes/eglot.el | 43 +++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 1b1302d689..2463f68f97 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -1501,29 +1501,38 @@ 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. + 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 type URIs untouched, `file-name-handler-alist' + ;; handlers can be used to dispatch them properly. + uri))) (defun eglot--snippet-expansion-fn () "Compute a function to expand snippets. -- 2.38.1 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0002-Eglot-warn-when-receiving-a-non-file-scheme-URI.patch >From a2b92859d0a327c843bcd677eede72c0c100821f Mon Sep 17 00:00:00 2001 From: dannyfreeman Date: Thu, 10 Nov 2022 13:05:49 -0500 Subject: [PATCH 2/2] Eglot: warn when receiving a non-file scheme URI * 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. Note that the file-name-handler operation checked is `nil' because we don't want to use a real one that may 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. Addresses bug#58790 --- lisp/progmodes/eglot.el | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lisp/progmodes/eglot.el b/lisp/progmodes/eglot.el index 2463f68f97..1850334b84 100644 --- a/lisp/progmodes/eglot.el +++ b/lisp/progmodes/eglot.el @@ -1530,6 +1530,8 @@ eglot--uri-to-path (substring retval 1) retval))) (concat remote-prefix normalized)) + (unless (find-file-name-handler uri nil) + (eglot--message "Received URI with unexpected scheme: %s" uri)) ;; Leave non-file type URIs untouched, `file-name-handler-alist' ;; handlers can be used to dispatch them properly. uri))) -- 2.38.1 --=-=-= Content-Type: text/plain -- Danny Freeman --=-=-=--