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 16:45:27 -0500 Message-ID: <87k042tqze.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> 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="25909"; mail-complaints-to="usenet@ciao.gmane.io" Cc: 58790@debbugs.gnu.org, dgutov@yandex.ru, felician.nemeth@gmail.com, =?UTF-8?Q?Jo=C3=A3o_?= =?UTF-8?Q?T=C3=A1vora?= , stefankangas@gmail.com To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Thu Nov 10 22:55:14 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 1otFVx-0006WM-E3 for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 10 Nov 2022 22:55:13 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1otFVn-0003k2-V4; Thu, 10 Nov 2022 16:55:03 -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 1otFVm-0003he-QO for bug-gnu-emacs@gnu.org; Thu, 10 Nov 2022 16:55: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 1otFVm-0007qt-Hw for bug-gnu-emacs@gnu.org; Thu, 10 Nov 2022 16:55:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1otFVl-0004zR-SZ for bug-gnu-emacs@gnu.org; Thu, 10 Nov 2022 16:55: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 21:55: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.166811729719169 (code B ref 58790); Thu, 10 Nov 2022 21:55:01 +0000 Original-Received: (at 58790) by debbugs.gnu.org; 10 Nov 2022 21:54:57 +0000 Original-Received: from localhost ([127.0.0.1]:44555 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1otFVh-0004z6-Ay for submit@debbugs.gnu.org; Thu, 10 Nov 2022 16:54:57 -0500 Original-Received: from out2.migadu.com ([188.165.223.204]:25357) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1otFVe-0004yw-SR for 58790@debbugs.gnu.org; Thu, 10 Nov 2022 16:54:56 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dfreeman.email; s=key1; t=1668117293; 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=UK5lZJKmqMm64qxAJci2nj4OIi9SloMYSiZTZHW9JmA=; b=upWrd8RYVmdpIvLJb3M9lK+QhobZpfxSF4BmLo3A4E1IkXe+C79RnL8enW0+c42ZPP22Fn 3cjberkiM67xXw+hznPD6qaySK/HcUvLiI2V0FgcjOguJgQCtdWi8XVbCPXfwwJeh2Mcxo jCn2V55SrBYGqa/4anJHWguPel4mYtY= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. In-reply-to: <83o7terf9a.fsf@gnu.org> 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:247552 Archived-At: --=-=-= Content-Type: text/plain Eli Zaretskii 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!!! --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Eglot-Only-handle-URIs-with-the-file-scheme.patch Content-Description: Only parse file: URIs >From a5b1b6b34d3d455e06757bbb1c10df8f81121f1f Mon Sep 17 00:00:00 2001 From: dannyfreeman 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 --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Eglot-warn-when-receiving-a-non-file-scheme-URI.patch Content-Description: Warn when unhandled file: URI is received >From 7fd1e7c4a264d74360d79c6cbee3f0e0aceeab5c Mon Sep 17 00:00:00 2001 From: dannyfreeman 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 --=-=-= Content-Type: text/plain Thank you, -- Danny Freeman --=-=-=--