From 71169144275f9c420c0b613429410af9e59f2ba9 Mon Sep 17 00:00:00 2001 From: Nicolas Goaziou Date: Fri, 9 Apr 2021 22:47:57 +0200 Subject: [PATCH] ox: Do not choke on incomplete OPTIONS items * lisp/ox.el (org-export--parse-option-keyword): Prevent "End of file during parsing" error when an OPTIONS item is incomplete. * lisp/org-lint.el (org-lint-unknown-options-item): Check for incomplete options items. * testing/lisp/test-org-lint.el (test-org-lint/unknown-options-item): Add test. --- lisp/org-lint.el | 8 ++++++-- lisp/ox.el | 2 +- testing/lisp/test-org-lint.el | 3 +++ 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/lisp/org-lint.el b/lisp/org-lint.el index 2e080cc13..ffeb9b2f7 100644 --- a/lisp/org-lint.el +++ b/lisp/org-lint.el @@ -671,7 +671,7 @@ Use \"export %s\" instead" (when (string= (org-element-property :key k) "OPTIONS") (let ((value (org-element-property :value k)) (start 0)) - (while (string-match "\\(.+?\\):\\((.*?)\\|\\S-*\\)[ \t]*" + (while (string-match "\\(.+?\\):\\((.*?)\\|\\S-+\\)?[ \t]*" value start) (setf start (match-end 0)) @@ -679,7 +679,11 @@ Use \"export %s\" instead" (unless (member item allowed) (push (list (org-element-property :post-affiliated k) (format "Unknown OPTIONS item \"%s\"" item)) - reports)))))))) + reports)) + (unless (match-string 2 value) + (push (list (org-element-property :post-affiliated k) + (format "Missing value for option item %S" item)) + reports)))))))) reports)) (defun org-lint-invalid-macro-argument-and-template (ast) diff --git a/lisp/ox.el b/lisp/ox.el index 050a8094d..4b3e39906 100644 --- a/lisp/ox.el +++ b/lisp/ox.el @@ -1386,7 +1386,7 @@ e.g., `org-export-create-backend'. It specifies which back-end specific items to read, if any." (let ((line (let ((s 0) alist) - (while (string-match "\\(.+?\\):\\((.*?)\\|\\S-*\\)[ \t]*" options s) + (while (string-match "\\(.+?\\):\\((.*?)\\|\\S-+\\)[ \t]*" options s) (setq s (match-end 0)) (push (cons (match-string 1 options) (read (match-string 2 options))) diff --git a/testing/lisp/test-org-lint.el b/testing/lisp/test-org-lint.el index f5d28b00f..97fede1ed 100644 --- a/testing/lisp/test-org-lint.el +++ b/testing/lisp/test-org-lint.el @@ -313,6 +313,9 @@ This is not a node property "Test `org-lint-unknown-options-item' checker." (should (org-test-with-temp-text "#+options: foobarbaz:t" + (org-lint '(unknown-options-item)))) + (should + (org-test-with-temp-text "#+options: H:" (org-lint '(unknown-options-item))))) (ert-deftest test-org-lint/invalid-macro-argument-and-template ()