Skip to content

Commit adbc9ed

Browse files
committed
URL escape # in notebook content paths
This avoids issues when trying to deal with Emacs auto-save files in notebook directories, paths like #bookmarks.org#. The notebook server believes the hash to be the start of the fragment component of a URL. * jupyter-rest-api.el (jupyter-api--sanitize-path): New function. (jupyter-api--strip-slashes): Remove. (jupyter-api-content-path): Use new function.
1 parent 6a0c7af commit adbc9ed

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

jupyter-rest-api.el

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -894,24 +894,25 @@ available via CLIENT."
894894

895895
;;; Contents API
896896

897-
;; TODO: Actually consider encoding/decoding
898-
;; https://jupyter-notebook.readthedocs.io/en/stable/extending/contents.html#filesystem-entities
897+
(autoload 'tramp-drop-volume-letter "tramp")
899898

900-
(defun jupyter-api--strip-slashes (path)
901-
(thread-last path
899+
(defun jupyter-api--sanitize-path (path)
900+
(thread-last
901+
path
902+
(tramp-drop-volume-letter)
903+
;; Strip slashes
902904
(replace-regexp-in-string "^/+" "")
903-
(replace-regexp-in-string "/+$" "")))
904-
905-
(autoload 'tramp-drop-volume-letter "tramp")
905+
(replace-regexp-in-string "/+$" "")
906+
;; Handle #
907+
(string-replace "#" "%23")))
906908

907-
;; See https://jupyter-notebook.readthedocs.io/en/stable/extending/contents.html#api-paths
909+
;; See https://jupyter-server.readthedocs.io/en/latest/developers/contents.html#api-paths
908910
(defsubst jupyter-api-content-path (file)
909911
"Return a sanitized path for locating FILE on a Jupyter REST server.
910912
Note, if FILE is not an absolute file name, it is expanded into
911913
one as if the `default-directory' where /."
912-
(jupyter-api--strip-slashes
913-
(tramp-drop-volume-letter
914-
(expand-file-name (file-local-name file) "/"))))
914+
(jupyter-api--sanitize-path
915+
(expand-file-name (file-local-name file) "/")))
915916

916917
(defun jupyter-api-get-file-model (client file &optional no-content type)
917918
"Send a request using CLIENT to get a model of FILE.

0 commit comments

Comments
 (0)