Kaynağa Gözat

org-element: Fix parsing of links with filled path

* lisp/org-element.el (org-element-link-parser): Remove all newline
  characters in path property.
* testing/lisp/test-org-element.el: Add test.
Nicolas Goaziou 12 yıl önce
ebeveyn
işleme
9f8f32c360
2 değiştirilmiş dosya ile 14 ekleme ve 3 silme
  1. 7 2
      lisp/org-element.el
  2. 7 1
      testing/lisp/test-org-element.el

+ 7 - 2
lisp/org-element.el

@@ -3002,11 +3002,16 @@ Assume point is at the beginning of the link."
 	(setq contents-begin (match-beginning 3)
 	      contents-end (match-end 3)
 	      link-end (match-end 0)
-	      ;; RAW-LINK is the original link.
+	      ;; RAW-LINK is the original link.  Expand any
+	      ;; abbreviation in it.
 	      raw-link (org-translate-link
 			(org-link-expand-abbrev
 			 (org-match-string-no-properties 1)))
-	      link (org-link-unescape raw-link))
+	      ;; Remove newline characters due to filling.  Headlines,
+	      ;; targets, radio targets and name affiliated keywords
+	      ;; cannot contain any.
+	      link (org-link-unescape
+		    (replace-regexp-in-string "\n" " " raw-link)))
 	;; Determine TYPE of link and set PATH accordingly.
 	(cond
 	 ;; File type.

+ 7 - 1
testing/lisp/test-org-element.el

@@ -1288,7 +1288,13 @@ e^{i\\pi}+1=0
 		   (org-element-map
 		    (org-element-parse-buffer) 'link
 		    (lambda (link) (org-element-property :type link))
-		    nil t nil t))))))
+		    nil t nil t)))))
+  ;; Corner case: links with filled path.
+  (should
+   (equal "a b"
+	  (org-test-with-temp-text "* a b\n[[a\nb]]"
+	    (progn (forward-line 1)
+		   (org-element-property :path (org-element-context)))))))
 
 
 ;;;; Macro