Fix missing null check for tangle links during export

* lisp/ob-tangle.el (org-babel-tangle--unbracketed-link): Add the let
bound variable l to the and statement to prevent l from being passed
to `string-match' in the event that it is nil.

When tangling nested noweb blocks during export it is possible for the
results of `org-store-link' to return nil.  This commit ensures that
the value returned for l is only passed to `string-match' when it is
non-nil, avoiding a `wrong-type-argument' (stringp nil) error.

Handling of comments and nesting of babel blocks is known to have
issues.  The bug is from 8a781d35dc
where new code was introduced to obtain the value for bare which was
not present in early code.  I'm guessing that the bug appears now
because `string-match' is called on l (aka link) at a point in time
when it was never previously called and it was thus masked because in
the old version it was impossible to call `string-match' when `link'
was nil because another variable was always nil, masking the issue.
This commit is contained in:
Tom Gillespie 2022-12-19 21:25:02 -05:00 committed by Ihor Radchenko
parent db34a7d837
commit a8c9f11757
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
1 changed files with 2 additions and 1 deletions

View File

@ -500,7 +500,8 @@ The PARAMS are the 3rd element of the info for the same src block."
(cl-letf (((symbol-function 'org-store-link-functions)
(lambda () nil)))
(org-store-link nil))))
(bare (and (string-match org-link-bracket-re l)
(bare (and l
(string-match org-link-bracket-re l)
(match-string 1 l))))
(when bare
(if (and org-babel-tangle-use-relative-file-links