ox-texinfo: Fix escaping commas inside commands with multiple arguments

* lisp/ox-texinfo.el (org-texinfo--sanitize-content): Sanitize commas
everywhere to make sure that we do not end up with text commas being
interpreted as argument separator in @command{arg1, arg2, ...}.  This
approach will produce @comma{} even when it is not necessary, but it
is the safest approach.
(org-texinfo-plain-text): Update the comment.
* testing/lisp/test-ox-texinfo.el (test-ox-texinfo/escape-special-characters):
New test.

Reported-by: 8dcc <8dcc.git@gmail.com>
Link: https://orgmode.org/list/87set58skp.fsf@gmail.com
This commit is contained in:
Ihor Radchenko 2024-10-19 10:27:04 +02:00
parent 8b4b89b14b
commit 39264d3d41
No known key found for this signature in database
GPG Key ID: 6470762A7DA11D8B
2 changed files with 27 additions and 3 deletions

View File

@ -588,8 +588,11 @@ export state, as a plist."
(defun org-texinfo--sanitize-content (text)
"Escape special characters in string TEXT.
Special characters are: @ { }"
(replace-regexp-in-string "[@{}]" "@\\&" text))
Special characters are: @ { } ,"
(thread-last
text
(replace-regexp-in-string "[@{}]" "@\\&")
(replace-regexp-in-string "," "@comma{}")))
(defun org-texinfo--wrap-float (value info &optional type label caption short)
"Wrap string VALUE within a @float command.
@ -1580,7 +1583,7 @@ contextual information."
"Transcode a TEXT string from Org to Texinfo.
TEXT is the string to transcode. INFO is a plist holding
contextual information."
;; First protect @, { and }.
;; First protect @, {, }, and commas (,).
(let ((output (org-texinfo--sanitize-content text)))
;; Activate smart quotes. Be sure to provide original TEXT string
;; since OUTPUT may have been modified.

View File

@ -445,5 +445,26 @@ body
(re-search-forward "Description")
(re-search-forward "@end defvar")))))))
;;; Escaping
(ert-deftest test-ox-texinfo/escape-special-characters ()
"Test escaping special characters."
(should
(org-test-with-temp-text
(string-join
(list "[[https://example.com][Foo, Bar]]"
"[[https://example.com][Foo, Bar}]]")
"\n")
(let ((export-buffer "*Test Texinfo Export*")
(org-export-show-temporary-export-buffer nil))
(org-export-to-buffer 'texinfo export-buffer
nil nil nil nil nil
#'texinfo-mode)
(with-current-buffer export-buffer
(goto-char (point-min))
(should (search-forward "@uref{https://example.com, Foo@comma{} Bar}"))
(should (search-forward "@uref{https://example.com, Foo@comma{} Bar@}}")))))))
(provide 'test-ox-texinfo)
;;; test-ox-texinfo.el end here