From a5df3cbeaeb4a5bc2608d58126f5ca6b32f35952 Mon Sep 17 00:00:00 2001 From: cage Date: Sat, 24 Jun 2023 12:01:31 +0200 Subject: [PATCH] - [GUI] fixed scanning for images that can be inlined; - prevented signaling an error when parsing an IRI to open the resource with an external program. --- src/gui/client/main-window.lisp | 16 ++++++++++------ src/gui/client/os-utils.lisp | 2 +- src/os-utils.lisp | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/gui/client/main-window.lisp b/src/gui/client/main-window.lisp index baa7261..379ea69 100644 --- a/src/gui/client/main-window.lisp +++ b/src/gui/client/main-window.lisp @@ -385,12 +385,16 @@ (slurp-non-text-data main-window iri :try-to-open nil)))))) (defun inline-image-p (link-value) - (or (re:scan "(?i)jpg$" link-value) - (re:scan "(?i)jpeg$" link-value) - (re:scan "(?i)png$" link-value) - (re:scan "(?i)gif$" link-value) - (re:scan "(?i)bmp$" link-value) - (re:scan "(?i)tga$" link-value))) + (a:when-let* ((parsed (iri:iri-parse link-value :null-on-error t)) + (path (uri:path parsed))) + (and (or (gemini-client:absolute-gemini-url-p link-value) + (not (iri:absolute-url-p link-value))) + (or (re:scan "(?i)jpg$" path) + (re:scan "(?i)jpeg$" path) + (re:scan "(?i)png$" path) + (re:scan "(?i)gif$" path) + (re:scan "(?i)bmp$" path) + (re:scan "(?i)tga$" path))))) (defun inline-possible-p (link-value) (inline-image-p link-value)) diff --git a/src/gui/client/os-utils.lisp b/src/gui/client/os-utils.lisp index 5d38fbb..4e2a993 100644 --- a/src/gui/client/os-utils.lisp +++ b/src/gui/client/os-utils.lisp @@ -20,7 +20,7 @@ (flet ((edit (file) (croatoan:end-screen) (os-utils:open-with-editor file))) - (alexandria::when-let* ((parsed-as-iri (iri:iri-parse resource)) + (alexandria::when-let* ((parsed-as-iri (iri:iri-parse resource :null-on-error t)) (parsed-no-fragment (iri:remove-fragment parsed-as-iri))) (let ((program (if (iri:absolute-url-p resource) (swconf:link-regex->program-to-use (text-utils:to-s parsed-no-fragment)) diff --git a/src/os-utils.lisp b/src/os-utils.lisp index 6147316..0f0851c 100644 --- a/src/os-utils.lisp +++ b/src/os-utils.lisp @@ -186,7 +186,7 @@ (flet ((edit (file) (croatoan:end-screen) (os-utils:open-with-editor file))) - (alexandria::when-let* ((parsed-as-iri (iri:iri-parse resource)) + (alexandria::when-let* ((parsed-as-iri (iri:iri-parse resource :null-on-error t)) (parsed-no-fragment (iri:remove-fragment parsed-as-iri))) (let ((program (if (iri:absolute-url-p resource) (swconf:link-regex->program-to-use (text-utils:to-s parsed-no-fragment))