diff --git a/README.org b/README.org index d122bdd..4d9fcbe 100644 --- a/README.org +++ b/README.org @@ -557,6 +557,7 @@ Simple links may also be written manually in either sexp or non-sexp form, like: *Fixes* + Predicate ~heading~ incorrectly matched strings as regular expressions, sometimes returning incorrect results. (See [[https://github.com/alphapapa/org-ql/discussions/410][discussion]]. Thanks to [[https://github.com/al3xandru][Alex Popescu]] for reporting.) ++ Predicates ~ancestor~ and ~parent~ did not normalize their sub-queries, sometimes returning incorrect results. ([[https://github.com/alphapapa/org-ql/issues/365][#365]]. Thanks to [[https://github.com/kofm][Gabriele Mongiano]] for reporting.) ** 0.8.4 diff --git a/org-ql.el b/org-ql.el index da4456e..2bc33f5 100644 --- a/org-ql.el +++ b/org-ql.el @@ -2077,7 +2077,7 @@ With KEYWORDS, return non-nil if its keyword is one of KEYWORDS." :normalizers ((`(,predicate-names ;; Avoid infinitely compiling already-compiled functions. ,(and query (guard (not (byte-code-function-p query))))) - `(ancestors ,(org-ql--query-predicate (rec query)))) + `(ancestors ,(org-ql--query-predicate (org-ql--normalize-query query)))) (`(,predicate-names) '(ancestors (lambda () t)))) :body (org-with-wide-buffer @@ -2089,7 +2089,7 @@ With KEYWORDS, return non-nil if its keyword is one of KEYWORDS." :normalizers ((`(,predicate-names ;; Avoid infinitely compiling already-compiled functions. ,(and query (guard (not (byte-code-function-p query))))) - `(parent ,(org-ql--query-predicate (rec query)))) + `(parent ,(org-ql--query-predicate (org-ql--normalize-query query)))) (`(,predicate-names) '(parent (lambda () t)))) :body (org-with-wide-buffer diff --git a/org-ql.info b/org-ql.info index 33a3dca..f17deee 100644 --- a/org-ql.info +++ b/org-ql.info @@ -1082,6 +1082,10 @@ File: README.info, Node: 085-pre, Next: 084, Up: Changelog discussion (https://github.com/alphapapa/org-ql/discussions/410). Thanks to Alex Popescu (https://github.com/al3xandru) for reporting.) + • Predicates ‘ancestor’ and ‘parent’ did not normalize their + sub-queries, sometimes returning incorrect results. (#365 + (https://github.com/alphapapa/org-ql/issues/365). Thanks to + Gabriele Mongiano (https://github.com/kofm) for reporting.)  File: README.info, Node: 084, Next: 083, Prev: 085-pre, Up: Changelog @@ -1984,45 +1988,45 @@ Node: Links38883 Node: Tips39570 Node: Changelog39894 Node: 085-pre40788 -Node: 08441175 -Node: 08341631 -Node: 08241972 -Node: 08142365 -Node: 0842786 -Node: 07445510 -Node: 07345733 -Node: 07246465 -Node: 07147384 -Node: 0748195 -Node: 06351061 -Node: 06251594 -Node: 06151901 -Node: 0652471 -Node: 05255527 -Node: 05155829 -Node: 0556254 -Node: 04957785 -Node: 04858067 -Node: 04758416 -Node: 04658825 -Node: 04559233 -Node: 04459594 -Node: 04359953 -Node: 04260156 -Node: 04160317 -Node: 0460564 -Node: 03264665 -Node: 03165068 -Node: 0365265 -Node: 02368565 -Node: 02268799 -Node: 02169079 -Node: 0269284 -Node: 0173362 -Node: Notes73463 -Node: Comparison with Org Agenda searches73625 -Node: org-sidebar74514 -Node: License74793 +Node: 08441444 +Node: 08341900 +Node: 08242241 +Node: 08142634 +Node: 0843055 +Node: 07445779 +Node: 07346002 +Node: 07246734 +Node: 07147653 +Node: 0748464 +Node: 06351330 +Node: 06251863 +Node: 06152170 +Node: 0652740 +Node: 05255796 +Node: 05156098 +Node: 0556523 +Node: 04958054 +Node: 04858336 +Node: 04758685 +Node: 04659094 +Node: 04559502 +Node: 04459863 +Node: 04360222 +Node: 04260425 +Node: 04160586 +Node: 0460833 +Node: 03264934 +Node: 03165337 +Node: 0365534 +Node: 02368834 +Node: 02269068 +Node: 02169348 +Node: 0269553 +Node: 0173631 +Node: Notes73732 +Node: Comparison with Org Agenda searches73894 +Node: org-sidebar74783 +Node: License75062  End Tag Table diff --git a/tests/test-org-ql.el b/tests/test-org-ql.el index 247fa78..8d2b84c 100644 --- a/tests/test-org-ql.el +++ b/tests/test-org-ql.el @@ -254,6 +254,18 @@ with keyword arg NOW in PLIST." (expect (org-ql--normalize-query "\"quoted phrase\"") :to-equal '(rifle :regexps '("\"quoted phrase\"")))) + (describe "Ancestor/Parent predicates" + ;; NOTE: Because the ancestor and parent predicates byte-compile their + ;; subquery predicates, we have to test the byte-compiled forms here. + (expect (org-ql--normalize-query '(ancestors "scheduled")) + ;; No colon after keyword, so not a predicate query. + :to-equal ;; '(ancestors (rifle :regexps '("scheduled"))) + `(ancestors #[nil "\300\301\302\"\207" [rifle :regexps ("scheduled")] 3])) + (expect (org-ql--normalize-query '(parent "scheduled")) + ;; No colon after keyword, so not a predicate query. + :to-equal ;; '(parent (rifle :regexps '("scheduled"))) + `(parent #[nil "\300\301\302\"\207" [rifle :regexps ("scheduled")] 3]))) + (describe "Plain strings" (it "normalizes plain strings to the default predicate (using AND)" (expect (org-ql--normalize-query '(and "string1" "string2"))