summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Goaziou <mail@nicolasgoaziou.fr>2017-03-01 22:19:04 +0100
committerNicolas Goaziou <mail@nicolasgoaziou.fr>2017-03-01 22:19:04 +0100
commita4eb60931aa942541dc6f59c50401c0faad60454 (patch)
treef752c02e0a99f34083bba76f57ebfbe90990511d
parente1fa353e0a0ae59701c119e9759f1d4000e193bd (diff)
downloadorg-mode-a4eb60931aa942541dc6f59c50401c0faad60454.tar.gz
ob-core: Properly escape Org syntax when inserting results
* lisp/ob-core.el (org-babel-examplify-region): Escape Org syntax before wrapping it. * testing/lisp/test-ob.el (test-ob/org-babel-insert-result): Add test. Renamed from `test-ob/org-babel-insert-result--improper-lists'. Reported-by: D M German <dmg@turingmachine.org>
-rw-r--r--lisp/ob-core.el4
-rw-r--r--testing/lisp/test-ob.el64
2 files changed, 64 insertions, 4 deletions
diff --git a/lisp/ob-core.el b/lisp/ob-core.el
index e835693..1e13aa5 100644
--- a/lisp/ob-core.el
+++ b/lisp/ob-core.el
@@ -2463,7 +2463,9 @@ file's directory then expand relative links."
(funcall maybe-cap "#+begin_example")
results-switches)
(funcall maybe-cap "#+begin_example\n")))
- (if (markerp end) (goto-char end) (forward-char (- end beg)))
+ (let ((p (point)))
+ (if (markerp end) (goto-char end) (forward-char (- end beg)))
+ (org-escape-code-in-region p (point)))
(insert (funcall maybe-cap "#+end_example\n")))))))))
(defun org-babel-update-block-body (new-body)
diff --git a/testing/lisp/test-ob.el b/testing/lisp/test-ob.el
index 1b6897f..13b3810 100644
--- a/testing/lisp/test-ob.el
+++ b/testing/lisp/test-ob.el
@@ -757,8 +757,8 @@ x
": 2"
(buffer-substring-no-properties (point-at-bol) (point-at-eol))))))
-(ert-deftest test-ob/org-babel-insert-result--improper-lists ()
- "Test `org-babel-insert-result' with improper lists."
+(ert-deftest test-ob/org-babel-insert-result ()
+ "Test `org-babel-insert-result' specifications."
;; Do not error when output is an improper list.
(should
(org-test-with-temp-text
@@ -767,7 +767,65 @@ x
'((1 . nil) (2 . 3))
#+END_SRC
"
- (org-babel-execute-maybe) t)))
+ (org-babel-execute-maybe) t))
+ ;; Escape headlines when producing an example block.
+ (should
+ (string-match-p
+ ",\\* Not an headline"
+ (org-test-with-temp-text
+ "
+<point>#+BEGIN_SRC emacs-lisp
+\"* Not an headline\n\n\n\n\n\n\n\n\n\n\"
+#+END_SRC
+"
+ (org-babel-execute-maybe)
+ (buffer-string))))
+ ;; Escape special syntax in example blocks.
+ (should
+ (string-match-p
+ ",#\\+END_SRC"
+ (org-test-with-temp-text
+ "
+<point>#+BEGIN_SRC emacs-lisp
+\"#+END_SRC\n\n\n\n\n\n\n\n\n\n\"
+#+END_SRC
+"
+ (org-babel-execute-maybe)
+ (buffer-string))))
+ ;; No escaping is done with other blocks or raw type.
+ (should
+ (string-match-p
+ ",\\* Not an headline"
+ (org-test-with-temp-text
+ "
+<point>#+BEGIN_SRC emacs-lisp
+\"* Not an headline\"
+#+END_SRC
+"
+ (org-babel-execute-maybe)
+ (buffer-string))))
+ (should
+ (string-match-p
+ ",\\* Not an headline"
+ (org-test-with-temp-text
+ "
+<point>#+BEGIN_SRC emacs-lisp :results raw
+\"* Not an headline\"
+#+END_SRC
+"
+ (org-babel-execute-maybe)
+ (buffer-string))))
+ (should-not
+ (string-match-p
+ ",\\* Not an headline"
+ (org-test-with-temp-text
+ "
+<point>#+BEGIN_SRC emacs-lisp :results drawer
+\"* Not an headline\"
+#+END_SRC
+"
+ (org-babel-execute-maybe)
+ (buffer-string)))))
(ert-deftest test-ob/remove-inline-result ()
"Test `org-babel-remove-inline-result' honors whitespace."