branch: elpa/gptel
commit 4a0d8056917a231d04306d96b1ef7ed3bd976cb8
Author: Henrik Ahlgren <[email protected]>
Commit: Henrik Ahlgren <[email protected]>

    gptel-org: Fix bug in link validation
    
    This fixes the following failing unit tests:
    gptel-test-media-link-parsing-md-1 and -2
    gptel-test-media-link-parsing-org-1 and -2
    
    * gptel-org.el (gptel-org--validate-link): Fix logic bug in setting
    `mime-valid'.  Alist `gptel--link-type-cache' was populated
    incorrectly: text files were marked as `("/foo/text.txt" . t)' and
    binary files as `("/foo/image.png" t . 10)'.  The text file case was
    wrong (t instead of nil), and the image had a number as a side effect
    of the fact that `gptel--file-binary-p' passes the number returned by
    `string-match-p' (insted of t) if the file name matches a known file
    type like `.png'.
    
    * gptel-request.el (gptel-markdown--validate-link): Fix the identical
    issue in the markdown variant of the function.
---
 gptel-org.el     | 18 +++++++++---------
 gptel-request.el | 18 +++++++++---------
 2 files changed, 18 insertions(+), 18 deletions(-)

diff --git a/gptel-org.el b/gptel-org.el
index c1f344bc43..32bafd09ea 100644
--- a/gptel-org.el
+++ b/gptel-org.el
@@ -398,15 +398,15 @@ first nil value in REST is guaranteed to be correct."
               (readablep (or (eq resource-type 'url) (file-remote-p path)
                              (file-readable-p path)))
               (mime-valid
-               (if (or (eq resource-type 'url)
-                       (cdr (with-memoization
-                                (alist-get (expand-file-name path)
-                                           gptel--link-type-cache
-                                           nil nil #'string=)
-                              (cons t (gptel--file-binary-p path)))))
-                   (gptel--model-mime-capable-p
-                    (setq mime (mailcap-file-name-to-mime-type path)))
-                 t)))
+               (or (eq resource-type 'url)
+                   (and (with-memoization
+                            (alist-get (expand-file-name path)
+                                       gptel--link-type-cache
+                                       nil nil #'string=)
+                          (if (gptel--file-binary-p path) t))
+                        (setq mime (mailcap-file-name-to-mime-type path))
+                        (gptel--model-mime-capable-p mime))
+                   t)))
         (list t link-type path resource-type user-check readablep mime-valid 
mime)
       (list nil link-type path resource-type user-check readablep mime-valid 
mime))))
 
diff --git a/gptel-request.el b/gptel-request.el
index a15852e5c3..d42f6858b0 100644
--- a/gptel-request.el
+++ b/gptel-request.el
@@ -2390,15 +2390,15 @@ first nil value in REST is guaranteed to be correct."
                              (file-remote-p path)
                              (file-readable-p path)))
               (mime-valid
-               (if (or (eq resource-type 'url)
-                       (cdr (with-memoization
-                                (alist-get (expand-file-name path)
-                                           gptel--link-type-cache
-                                           nil nil #'string=)
-                              (cons t (gptel--file-binary-p path)))))
-                   (gptel--model-mime-capable-p
-                    (setq mime (mailcap-file-name-to-mime-type path)))
-                 t)))
+               (or (eq resource-type 'url)
+                   (and (with-memoization
+                            (alist-get (expand-file-name path)
+                                       gptel--link-type-cache
+                                       nil nil #'string=)
+                          (if (gptel--file-binary-p path) t))
+                        (setq mime (mailcap-file-name-to-mime-type path))
+                        (gptel--model-mime-capable-p mime))
+                   t)))
         (list t link-type path resource-type user-check readablep mime-valid 
mime)
       (list nil link-type path resource-type user-check readablep mime-valid 
mime))))
 

Reply via email to