emacs-elpa-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[elpa] externals/eglot 33e83ba 44/49: Fix #638: convert colon to hex in


From: Stefan Monnier
Subject: [elpa] externals/eglot 33e83ba 44/49: Fix #638: convert colon to hex in URI
Date: Wed, 17 Mar 2021 18:41:50 -0400 (EDT)

branch: externals/eglot
commit 33e83ba4a7a3f704e44e9b49373afe842e4b50b8
Author: Theodor Thornhill <theo@thornhill.no>
Commit: João Távora <joaotavora@gmail.com>

    Fix #638: convert colon to hex in URI
    
    On windows, in the path portion of the URI, ':' must be hexified to
    '%3A'.  In the URL scheme, the ':' stays.
    
    * eglot.el (eglot--uri-path-allowed-chars): define what characters are
    allowed in path portion of URI.
    
    * eglot.el (eglot--path-to-uri): ensure colon in 'file://' stays, but
    and others are hexified.
    
    Co-authored-by: João Távora
---
 eglot-tests.el |  8 +++++++-
 eglot.el       | 14 ++++++++++----
 2 files changed, 17 insertions(+), 5 deletions(-)

diff --git a/eglot-tests.el b/eglot-tests.el
index 9f9b428..b76fe16 100644
--- a/eglot-tests.el
+++ b/eglot-tests.el
@@ -1107,7 +1107,7 @@ will assume it exists."
   ;; Set up a loopback TRAMP method that’s just a shell so the remote
   ;; host is really just the local host.
   (let ((tramp-remote-path (cons 'tramp-own-remote-path tramp-remote-path))
-       (tramp-methods '(("loopback"
+        (tramp-methods '(("loopback"
                           (tramp-login-program "/bin/sh")
                           (tramp-remote-shell "/bin/sh")
                           (tramp-remote-shell-login ("-l"))
@@ -1118,6 +1118,12 @@ will assume it exists."
     ;; method, fixtures will be automatically made “remote".
     (eglot-tests--auto-detect-running-server-1)))
 
+(ert-deftest eglot--path-to-uri-windows ()
+  (should (string-prefix-p "file:///"
+                           (eglot--path-to-uri "c:/Users/Foo/bar.lisp")))
+  (should (string-suffix-p "c%3A/Users/Foo/bar.lisp"
+                           (eglot--path-to-uri "c:/Users/Foo/bar.lisp"))))
+
 (provide 'eglot-tests)
 ;;; eglot-tests.el ends here
 
diff --git a/eglot.el b/eglot.el
index e0896c8..d4300e1 100644
--- a/eglot.el
+++ b/eglot.el
@@ -1190,13 +1190,19 @@ If optional MARKER, return a marker instead"
           (funcall eglot-move-to-column-function col)))
       (if marker (copy-marker (point-marker)) (point)))))
 
+(defconst eglot--uri-path-allowed-chars
+  (let ((vec (copy-sequence url-path-allowed-chars)))
+    (aset vec ?: nil) ;; see github#639
+    vec)
+  "Like `url-path-allows-chars' but more restrictive.")
+
 (defun eglot--path-to-uri (path)
   "URIfy PATH."
-  (url-hexify-string
-   (concat "file://" (if (eq system-type 'windows-nt) "/")
+  (concat "file://" (if (eq system-type 'windows-nt) "/")
+          (url-hexify-string
            ;; Again watch out for trampy paths.
-           (directory-file-name (file-local-name (file-truename path))))
-   url-path-allowed-chars))
+           (directory-file-name (file-local-name (file-truename path))) 
+           eglot--uri-path-allowed-chars)))
 
 (defun eglot--uri-to-path (uri)
   "Convert URI to file path, helped by `eglot--current-server'."



reply via email to

[Prev in Thread] Current Thread [Next in Thread]