Found a bug when a project's base directory has regexp characters in it. This probably happens often for `.' but nobody cares because that likely returns the correct result. But I had a `+' in my project's base directory name.

I've included the revised function below with my change "subtly" marked by:

This being my first time creating an org project, I kept thinking it was something with my project config. Finally I decided it was a bug as I got a test project to work.

In order to file a coherent bug report, I tried to narrow the bug down to an easy test case. It was when I got it down to a bug in `string-match' that I started to think there might be another problem.

It still took me some trial and error with the filenames before -thwap-
I realized that the `+' in the filename was causing the problem.

Without making a promise about my accuracy, I did search for other calls to `string-match' in org-publish.el and thought that they all looked good. I think the problem can only occur when a regexp is being created from a non-regexp string passed in by the user. In this case, a file path.

I did not search in any other org source files.


(defun org-publish-get-project-from-filename (filename &optional up)
  "Return the project that FILENAME belongs to."
  (let* ((filename (expand-file-name filename))

    (catch 'p-found
      (dolist (prj org-publish-project-alist)
        (unless (plist-get (cdr prj) :components)
          ;; [[info:org:Selecting%20files]] shows how this is supposed to work:
          (let* ((r (plist-get (cdr prj) :recursive))
                 (b (regexp-quote             <-- !!!!!HERE!!!!!
                     (expand-file-name (file-name-as-directory
(plist-get (cdr prj) :base-directory)))))
                 (x (or (plist-get (cdr prj) :base-extension) "org"))
                 (e (plist-get (cdr prj) :exclude))
                 (i (plist-get (cdr prj) :include))
                 (xm (concat "^" b (if r ".+" "[^/]+") "\\.\\(" x "\\)$")))
                  i (member filename
                             (lambda (file) (expand-file-name file b))
                    (not (and e (string-match e filename)))
                    (string-match xm filename)))
              (setq project-name (car prj))
              (throw 'p-found project-name))))))
    (when up
      (dolist (prj org-publish-project-alist)
        (if (member project-name (plist-get (cdr prj) :components))
            (setq project-name (car prj)))))
    (assoc project-name org-publish-project-alist)))

Neil Smithline
Proud GNU Emacs user since 1986, v. 18.24.

Reply via email to