Browse Source

Fix tangling of org block with nested source block

* lisp/ob-tangle.el (org-babel-tangle-single-block): Prevent double unescaping
of source block by removing unnecessary call to `org-unescape-code-in-string'.

* testing/lisp/test-ob-tangle.el (ob-tangle/nested-block) New function.
thibault 7 years ago
parent
commit
1613153aac
2 changed files with 28 additions and 4 deletions
  1. 3 4
      lisp/ob-tangle.el
  2. 25 0
      testing/lisp/test-ob-tangle.el

+ 3 - 4
lisp/ob-tangle.el

@@ -494,10 +494,9 @@ non-nil, return the full association list to be used by
 		  link)
 		source-name
 		params
-		(org-unescape-code-in-string
-		 (if org-src-preserve-indentation
-		     (org-trim body t)
-		   (org-trim (org-remove-indentation body))))
+		(if org-src-preserve-indentation
+		    (org-trim body t)
+		  (org-trim (org-remove-indentation body)))
 		comment)))
     (if only-this-block
 	(list (cons src-lang (list result)))

+ 25 - 0
testing/lisp/test-ob-tangle.el

@@ -197,6 +197,31 @@ another block
           (org-babel-tangle-jump-to-org)
           (buffer-string)))))))
 
+(ert-deftest ob-tangle/nested-block ()
+  "Test tangling of org file with nested block."
+  (should
+   (string=
+    "#+begin_src org
+,#+begin_src emacs-lisp
+1
+,#+end_src
+#+end_src
+"
+    (org-test-with-temp-text-in-file
+        "#+header: :tangle \"test-ob-tangle.org\"
+#+begin_src org
+,#+begin_src org
+,,#+begin_src emacs-lisp
+1
+,,#+end_src
+,#+end_src
+#+end_src"
+      (unwind-protect
+          (progn (org-babel-tangle)
+                 (with-temp-buffer (insert-file-contents "test-ob-tangle.org")
+                                   (buffer-string)))
+        (delete-file "test-ob-tangle.org"))))))
+
 (provide 'test-ob-tangle)
 
 ;;; test-ob-tangle.el ends here