Skip to content

Commit

Permalink
Fix: (link) Don't match against null groups
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
alphapapa committed Nov 7, 2024
1 parent 3cfc77d commit 0e68cc9
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 51 deletions.
3 changes: 2 additions & 1 deletion README.org
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,8 @@ Simple links may also be written manually in either sexp or non-sexp form, like:

** 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

Expand Down
14 changes: 9 additions & 5 deletions org-ql.el
Original file line number Diff line number Diff line change
Expand Up @@ -1626,11 +1626,15 @@ any link is found."
(or (null description)
(string-match-p description (match-string org-ql-link-description-group)))))
(_ (if (and description target)
(and (string-match-p target (match-string 1))
(string-match-p description (match-string org-ql-link-description-group)))
(or (string-match-p description-or-target (match-string 1))
(string-match-p description-or-target
(match-string org-ql-link-description-group)))))))))
(and (and (match-string 1)
(string-match-p target (match-string 1)))
(and (match-string org-ql-link-description-group)
(string-match-p description (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)
"Return non-nil if each of strings is found in the entry or its outline path.
Expand Down
94 changes: 49 additions & 45 deletions org-ql.info
Original file line number Diff line number Diff line change
Expand Up @@ -1086,7 +1086,11 @@ File: README.info, Node: 0810-pre, Next: 089, Up: Changelog
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
Expand Down Expand Up @@ -2093,50 +2097,50 @@ Node: Links38955
Node: Tips39642
Node: Changelog39966
Node: 0810-pre40932
Node: 08941047
Node: 08842191
Node: 08743267
Node: 08644495
Node: 08544729
Node: 08445385
Node: 08345837
Node: 08246178
Node: 08146571
Node: 0846994
Node: 07449720
Node: 07349945
Node: 07250679
Node: 07151600
Node: 0752411
Node: 06355277
Node: 06255810
Node: 06156117
Node: 0656687
Node: 05259743
Node: 05160045
Node: 0560470
Node: 04962001
Node: 04862283
Node: 04762632
Node: 04663041
Node: 04563449
Node: 04463810
Node: 04364169
Node: 04264372
Node: 04164533
Node: 0464780
Node: 03268881
Node: 03169284
Node: 0369481
Node: 02372781
Node: 02273015
Node: 02173295
Node: 0273500
Node: 0177578
Node: Notes77679
Node: Comparison with Org Agenda searches77841
Node: org-sidebar78730
Node: License79009
Node: 08941297
Node: 08842441
Node: 08743517
Node: 08644745
Node: 08544979
Node: 08445635
Node: 08346087
Node: 08246428
Node: 08146821
Node: 0847244
Node: 07449970
Node: 07350195
Node: 07250929
Node: 07151850
Node: 0752661
Node: 06355527
Node: 06256060
Node: 06156367
Node: 0656937
Node: 05259993
Node: 05160295
Node: 0560720
Node: 04962251
Node: 04862533
Node: 04762882
Node: 04663291
Node: 04563699
Node: 04464060
Node: 04364419
Node: 04264622
Node: 04164783
Node: 0465030
Node: 03269131
Node: 03169534
Node: 0369731
Node: 02373031
Node: 02273265
Node: 02173545
Node: 0273750
Node: 0177828
Node: Notes77929
Node: Comparison with Org Agenda searches78091
Node: org-sidebar78980
Node: License79259

End Tag Table

Expand Down

0 comments on commit 0e68cc9

Please sign in to comment.