Fix: (link) Don't match against null groups

e.g. in a source block containing Bash shell code like:

  [[ -z $data ]]

The matched groups could be null, since it's not actually an Org link,
so calling STRING-MATCH-P on them would signal an error.

Reported-by: John Wiegley <jwiegley@gmail.com>
This commit is contained in:
Adam Porter 2024-11-06 21:20:30 -06:00
parent 3cfc77d2ff
commit 0e68cc9fac
3 changed files with 60 additions and 51 deletions

View file

@ -555,7 +555,8 @@ Simple links may also be written manually in either sexp or non-sexp form, like:
** 0.8.10-pre ** 0.8.10-pre
Nothing new yet. *Fixes*
+ Predicate ~link~ could signal an error when searching text that is mistakenly recognized as an Org link (e.g. Bash double-bracket constructs in a source block). (Thanks to [[https://github.com/jwiegley][John Wiegley]] for reporting.)
** 0.8.9 ** 0.8.9

View file

@ -1626,11 +1626,15 @@ any link is found."
(or (null description) (or (null description)
(string-match-p description (match-string org-ql-link-description-group))))) (string-match-p description (match-string org-ql-link-description-group)))))
(_ (if (and description target) (_ (if (and description target)
(and (string-match-p target (match-string 1)) (and (and (match-string 1)
(string-match-p description (match-string org-ql-link-description-group))) (string-match-p target (match-string 1)))
(or (string-match-p description-or-target (match-string 1)) (and (match-string org-ql-link-description-group)
(string-match-p description-or-target (string-match-p description (match-string org-ql-link-description-group))))
(match-string org-ql-link-description-group))))))))) (or (and (match-string 1)
(string-match-p description-or-target (match-string 1)))
(and (match-string org-ql-link-description-group)
(string-match-p description-or-target
(match-string org-ql-link-description-group))))))))))
(org-ql-defpred (rifle smart) (&rest strings) (org-ql-defpred (rifle smart) (&rest strings)
"Return non-nil if each of strings is found in the entry or its outline path. "Return non-nil if each of strings is found in the entry or its outline path.

View file

@ -1086,7 +1086,11 @@ File: README.info, Node: 0810-pre, Next: 089, Up: Changelog
5.1 0.8.10-pre 5.1 0.8.10-pre
============== ==============
Nothing new yet. *Fixes*
• Predicate link could signal an error when searching text that is
mistakenly recognized as an Org link (e.g. Bash double-bracket
constructs in a source block). (Thanks to John Wiegley
(https://github.com/jwiegley) for reporting.)
 
File: README.info, Node: 089, Next: 088, Prev: 0810-pre, Up: Changelog File: README.info, Node: 089, Next: 088, Prev: 0810-pre, Up: Changelog
@ -2093,50 +2097,50 @@ Node: Links38955
Node: Tips39642 Node: Tips39642
Node: Changelog39966 Node: Changelog39966
Node: 0810-pre40932 Node: 0810-pre40932
Node: 08941047 Node: 08941297
Node: 08842191 Node: 08842441
Node: 08743267 Node: 08743517
Node: 08644495 Node: 08644745
Node: 08544729 Node: 08544979
Node: 08445385 Node: 08445635
Node: 08345837 Node: 08346087
Node: 08246178 Node: 08246428
Node: 08146571 Node: 08146821
Node: 0846994 Node: 0847244
Node: 07449720 Node: 07449970
Node: 07349945 Node: 07350195
Node: 07250679 Node: 07250929
Node: 07151600 Node: 07151850
Node: 0752411 Node: 0752661
Node: 06355277 Node: 06355527
Node: 06255810 Node: 06256060
Node: 06156117 Node: 06156367
Node: 0656687 Node: 0656937
Node: 05259743 Node: 05259993
Node: 05160045 Node: 05160295
Node: 0560470 Node: 0560720
Node: 04962001 Node: 04962251
Node: 04862283 Node: 04862533
Node: 04762632 Node: 04762882
Node: 04663041 Node: 04663291
Node: 04563449 Node: 04563699
Node: 04463810 Node: 04464060
Node: 04364169 Node: 04364419
Node: 04264372 Node: 04264622
Node: 04164533 Node: 04164783
Node: 0464780 Node: 0465030
Node: 03268881 Node: 03269131
Node: 03169284 Node: 03169534
Node: 0369481 Node: 0369731
Node: 02372781 Node: 02373031
Node: 02273015 Node: 02273265
Node: 02173295 Node: 02173545
Node: 0273500 Node: 0273750
Node: 0177578 Node: 0177828
Node: Notes77679 Node: Notes77929
Node: Comparison with Org Agenda searches77841 Node: Comparison with Org Agenda searches78091
Node: org-sidebar78730 Node: org-sidebar78980
Node: License79009 Node: License79259
 
End Tag Table End Tag Table