From d7f074aa347527128d280b1868b9d742b0cc3e21 Mon Sep 17 00:00:00 2001 From: cage Date: Sat, 3 Apr 2021 13:04:40 +0200 Subject: [PATCH] - [gemini] percent encoded paths when exploring local filesystems. --- src/open-message-link-window.lisp | 11 ++++++----- src/program-events.lisp | 22 +++++++++++++--------- src/ui-goodies.lisp | 2 +- 3 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/open-message-link-window.lisp b/src/open-message-link-window.lisp index 74958bd..306b6a6 100644 --- a/src/open-message-link-window.lisp +++ b/src/open-message-link-window.lisp @@ -71,8 +71,9 @@ *open-message-link-window*)) (defun open-message-link (url enqueue) - (let* ((parsed (iri:iri-parse url)) - (scheme (uri:scheme parsed))) + (let* ((parsed (iri:iri-parse url)) + (scheme (uri:scheme parsed)) + (decoded-path (percent-decode url))) (cond ((string= gemini-constants:+gemini-scheme+ scheme) (let ((program-events:*process-events-immediately* t) @@ -84,14 +85,14 @@ (program-events:push-event event) (gemini-viewer:request url :enqueue enqueue :use-cached-file-if-exists t))) - ((fs:dirp url) + ((fs:dirp decoded-path) (let ((program-events:*process-events-immediately* t) (event (make-instance 'program-events:gemini-push-behind-downloading-event :priority program-events:+maximum-event-priority+))) (program-events:push-event event) - (gemini-viewer:load-gemini-url url :give-focus-to-message-window nil))) + (gemini-viewer:load-gemini-url decoded-path :give-focus-to-message-window nil))) (t - (os-utils:open-resource-with-external-program url nil))))) + (os-utils:open-resource-with-external-program decoded-path nil))))) (defclass open-links-window () ((links diff --git a/src/program-events.lisp b/src/program-events.lisp index 5087329..3a10802 100644 --- a/src/program-events.lisp +++ b/src/program-events.lisp @@ -1005,10 +1005,13 @@ (defmethod process-event ((object gemini-request-event)) (tui:with-notify-errors - (with-accessors ((url url) + (with-accessors ((url url) ; if a local file *not* percent encoded (give-focus-to-message-window-p give-focus-to-message-window-p) (use-cached-file-if-exists use-cached-file-if-exists)) object - (let ((window specials:*message-window*)) + (let ((window specials:*message-window*) + (local-path (if (text-utils:percent-encoded-p url) + (text-utils:percent-decode url) + url))) (setf (windows:keybindings window) keybindings:*gemini-message-keymap*) (when give-focus-to-message-window-p @@ -1016,8 +1019,8 @@ (cond ((gemini-client:absolute-gemini-url-p url) (gemini-viewer:request url :use-cached-file-if-exists use-cached-file-if-exists)) - ((fs:dirp url) - (let* ((index-path (uri:normalize-path (fs:prepend-pwd url))) + ((fs:dirp local-path) + (let* ((index-path (uri:normalize-path (fs:prepend-pwd local-path))) (all-paths (mapcar #'uri:normalize-path (fs:collect-children index-path))) (raw-text (with-output-to-string (stream) @@ -1031,10 +1034,11 @@ (dir-symbol (swconf:directory-symbol)) (link-label (if dirp (text-utils:strcat path " " dir-symbol) - path))) + path)) + (encoded-path (gemini-client::percent-encode-path path))) (format stream "~a~%" - (gemini-parser:make-gemini-link path + (gemini-parser:make-gemini-link encoded-path link-label)))))) (parsed (gemini-parser:parse-gemini-file raw-text)) (links (gemini-parser:sexp->links parsed @@ -1049,8 +1053,8 @@ (refresh-gemini-message-window links raw-text text nil) (windows:draw window))) (t - (let* ((file-string (fs:slurp-file url)) - (parent-dir (fs:parent-dir-path url)) + (let* ((file-string (fs:slurp-file local-path)) + (parent-dir (fs:parent-dir-path local-path)) (parsed (gemini-parser:parse-gemini-file file-string)) (links (gemini-parser:sexp->links parsed nil @@ -1060,7 +1064,7 @@ (text (gemini-parser:sexp->text parsed gemini-client:*gemini-page-theme*))) (gemini-viewer:maybe-initialize-metadata window) - (gemini-viewer:add-url-to-history window url) + (gemini-viewer:add-url-to-history window local-path) (refresh-gemini-message-window links file-string text nil) (windows:draw window)))))))) diff --git a/src/ui-goodies.lisp b/src/ui-goodies.lisp index 834e6cc..cd1fbc1 100644 --- a/src/ui-goodies.lisp +++ b/src/ui-goodies.lisp @@ -1778,7 +1778,7 @@ open-message-link-window:open-message-link" (defun open-gemini-address () "Ask for a gemini address and try to load it" (flet ((on-input-complete (url) - (gemini-viewer:load-gemini-url url + (gemini-viewer:load-gemini-url (trim-blanks url) :use-cached-file-if-exists t :priority program-events:+maximum-event-priority+)))