emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* Bug: XML entities in the ox-rss exporter
@ 2016-05-17 19:20 Arun Isaac
  2016-05-24 20:48 ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Arun Isaac @ 2016-05-17 19:20 UTC (permalink / raw)
  To: emacs-org


The ox-rss exporter does not replace characters (such as < , > , etc.)
by their corresponding XML entities (&lt; , &gt; , etc.) in the <title>
field of the generated XML.

For example, the following org file, when exported, will produce invalid
XML where the <title> field still contains the disallowed "<" character.

----- org file begins here -----
* Foo <- Bar

Some text
----- org file ends here -----

I'm guessing the ox-rss backend similarly fails to handle XML entities
in other fields as well.

I can provide a patch for this. But, do I use an external library like
xmlgen (https://github.com/philjackson/xmlgen), or do I write my own
find and replace functions like those in ox-html? I think the xmlgen
based approach provides better abstraction and avoids reinventing XML
generation. But, it will introduce an additional dependency.

Please provide thoughts and suggestions.

Thank you,
Arun Isaac.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Bug: XML entities in the ox-rss exporter
  2016-05-17 19:20 Bug: XML entities in the ox-rss exporter Arun Isaac
@ 2016-05-24 20:48 ` Nicolas Goaziou
  2016-05-25 10:12   ` Arun Isaac
  0 siblings, 1 reply; 6+ messages in thread
From: Nicolas Goaziou @ 2016-05-24 20:48 UTC (permalink / raw)
  To: Arun Isaac; +Cc: emacs-org

Hello,

Arun Isaac <theroarofthedragon@gmail.com> writes:

> I can provide a patch for this. 

Thank you.

> But, do I use an external library like xmlgen
> (https://github.com/philjackson/xmlgen), or do I write my own find and
> replace functions like those in ox-html?

Since "ox-rss.el" loads "ox-html", could you re-use code in the latter?

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Bug: XML entities in the ox-rss exporter
  2016-05-24 20:48 ` Nicolas Goaziou
@ 2016-05-25 10:12   ` Arun Isaac
  2016-05-26 10:17     ` Arun Isaac
  0 siblings, 1 reply; 6+ messages in thread
From: Arun Isaac @ 2016-05-25 10:12 UTC (permalink / raw)
  To: emacs-org


[-- Attachment #1.1: Type: text/plain, Size: 798 bytes --]


>> I can provide a patch for this. 

Please find attached the patch.

> Since "ox-rss.el" loads "ox-html", could you re-use code in the latter?

I think even ox-html could benefit from using an XML/HTML generation
library that can convert s-expressions to XML/HTML. xml.el has
`xml-parse-region' to convert XML strings to an s-expression tree, but
unfortunately has no function to do the inverse, that is, convert an
s-expression tree to an XML string. If it had such a function, we
needn't have to depend on an external library such as xmlgen, and things
would have been more convenient.

Anyways, for now, I have implemented a patch which uses
`org-rss-plain-text' (which, in turn uses `org-html-encode-plain-text')
to encode the disallowed characters to their XML entities.


[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: ox-rss-Encode-characters-to-their-XML-entities.patch --]
[-- Type: text/x-diff, Size: 1999 bytes --]

From 2b310b32234e6193154c9850d51aaa8ed312f2df Mon Sep 17 00:00:00 2001
From: Arun Isaac <theroarofthedragon@gmail.com>
Date: Wed, 25 May 2016 15:11:34 +0530
Subject: [PATCH] ox-rss: Encode characters to their XML entities

* contrib/lisp/ox-rss.el (org-rss-build-channel-info, org-rss-headline):
  Encode disallowed characters in `title' to their XML entities

The `title' field is user specified and may contain characters such as
"&", "<" or ">" that are disallowed in XML. These characters should be
encoded into their corresponding XML entities.
---
 contrib/lisp/ox-rss.el | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/contrib/lisp/ox-rss.el b/contrib/lisp/ox-rss.el
index 0c4a2f2..95d20ec 100644
--- a/contrib/lisp/ox-rss.el
+++ b/contrib/lisp/ox-rss.el
@@ -248,12 +248,13 @@ communication channel."
 			    (format-time-string
 			     "%a, %d %b %Y %H:%M:%S %z"
 			     (org-time-string-to-time pubdate0)))))
-	     (title (or (org-element-property :RSS_TITLE headline)
-			(replace-regexp-in-string
-			 org-bracket-link-regexp
-			 (lambda (m) (or (match-string 3 m)
-					 (match-string 1 m)))
-			 (org-element-property :raw-value headline))))
+	     (title (org-rss-plain-text
+		     (or (org-element-property :RSS_TITLE headline)
+			 (replace-regexp-in-string
+			  org-bracket-link-regexp
+			  (lambda (m) (or (match-string 3 m)
+					  (match-string 1 m)))
+			  (org-element-property :raw-value headline))) info))
 	     (publink
 	      (or (and hl-perm (concat (or hl-home hl-pdir) hl-perm))
 		  (concat
@@ -318,7 +319,7 @@ as a communication channel."
 (defun org-rss-build-channel-info (info)
   "Build the RSS channel information."
   (let* ((system-time-locale "C")
-	 (title (plist-get info :title))
+	 (title (org-rss-plain-text (or (plist-get info :title) "") info))
 	 (email (org-export-data (plist-get info :email) info))
 	 (author (and (plist-get info :with-author)
 		      (let ((auth (plist-get info :author)))
-- 
2.8.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: Bug: XML entities in the ox-rss exporter
  2016-05-25 10:12   ` Arun Isaac
@ 2016-05-26 10:17     ` Arun Isaac
  2016-05-26 12:05       ` Arun Isaac
  0 siblings, 1 reply; 6+ messages in thread
From: Arun Isaac @ 2016-05-26 10:17 UTC (permalink / raw)
  To: emacs-org

[-- Attachment #1: Type: text/plain, Size: 144 bytes --]


> Please find attached the patch.

I think my patch introduces a bug in `org-rss-build-channel-info'. I'll
fix this and send a new patch soon.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: Bug: XML entities in the ox-rss exporter
  2016-05-26 10:17     ` Arun Isaac
@ 2016-05-26 12:05       ` Arun Isaac
  2016-05-26 13:22         ` Nicolas Goaziou
  0 siblings, 1 reply; 6+ messages in thread
From: Arun Isaac @ 2016-05-26 12:05 UTC (permalink / raw)
  To: emacs-org


[-- Attachment #1.1: Type: text/plain, Size: 251 bytes --]


> I think my patch introduces a bug in `org-rss-build-channel-info'. I'll
> fix this and send a new patch soon.

I didn't realize (plist-get info :title) returns a list, and not a
string.  I have now fixed the bug. Please find attached a new patch.


[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 472 bytes --]

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: ox-rss-Encode-characters-to-their-XML-entities.patch --]
[-- Type: text/x-diff, Size: 1988 bytes --]

From 58c290c9308f07e44bf893331ccf9d9c5d255e04 Mon Sep 17 00:00:00 2001
From: Arun Isaac <theroarofthedragon@gmail.com>
Date: Thu, 26 May 2016 17:24:29 +0530
Subject: [PATCH] ox-rss: Encode characters to their XML entities

* contrib/lisp/ox-rss.el (org-rss-build-channel-info, org-rss-headline):
  Encode disallowed characters in `title' to their XML entities

The `title' field is user specified and may contain characters such as
"&", "<" or ">" that are disallowed in XML. These characters should be
encoded into their corresponding XML entities.
---
 contrib/lisp/ox-rss.el | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/contrib/lisp/ox-rss.el b/contrib/lisp/ox-rss.el
index 0c4a2f2..44ee8db 100644
--- a/contrib/lisp/ox-rss.el
+++ b/contrib/lisp/ox-rss.el
@@ -248,12 +248,13 @@ communication channel."
 			    (format-time-string
 			     "%a, %d %b %Y %H:%M:%S %z"
 			     (org-time-string-to-time pubdate0)))))
-	     (title (or (org-element-property :RSS_TITLE headline)
-			(replace-regexp-in-string
-			 org-bracket-link-regexp
-			 (lambda (m) (or (match-string 3 m)
-					 (match-string 1 m)))
-			 (org-element-property :raw-value headline))))
+	     (title (org-rss-plain-text
+		     (or (org-element-property :RSS_TITLE headline)
+			 (replace-regexp-in-string
+			  org-bracket-link-regexp
+			  (lambda (m) (or (match-string 3 m)
+					  (match-string 1 m)))
+			  (org-element-property :raw-value headline))) info))
 	     (publink
 	      (or (and hl-perm (concat (or hl-home hl-pdir) hl-perm))
 		  (concat
@@ -318,7 +319,7 @@ as a communication channel."
 (defun org-rss-build-channel-info (info)
   "Build the RSS channel information."
   (let* ((system-time-locale "C")
-	 (title (plist-get info :title))
+	 (title (org-export-data (plist-get info :title) info))
 	 (email (org-export-data (plist-get info :email) info))
 	 (author (and (plist-get info :with-author)
 		      (let ((auth (plist-get info :author)))
-- 
2.8.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: Bug: XML entities in the ox-rss exporter
  2016-05-26 12:05       ` Arun Isaac
@ 2016-05-26 13:22         ` Nicolas Goaziou
  0 siblings, 0 replies; 6+ messages in thread
From: Nicolas Goaziou @ 2016-05-26 13:22 UTC (permalink / raw)
  To: Arun Isaac; +Cc: emacs-org

Hello,

Arun Isaac <theroarofthedragon@gmail.com> writes:

> Subject: [PATCH] ox-rss: Encode characters to their XML entities
>
> * contrib/lisp/ox-rss.el (org-rss-build-channel-info, org-rss-headline):
>   Encode disallowed characters in `title' to their XML entities
>
> The `title' field is user specified and may contain characters such as
> "&", "<" or ">" that are disallowed in XML. These characters should be
> encoded into their corresponding XML entities.

Applied. Thank you.

Regards,

-- 
Nicolas Goaziou

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2016-05-26 13:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-05-17 19:20 Bug: XML entities in the ox-rss exporter Arun Isaac
2016-05-24 20:48 ` Nicolas Goaziou
2016-05-25 10:12   ` Arun Isaac
2016-05-26 10:17     ` Arun Isaac
2016-05-26 12:05       ` Arun Isaac
2016-05-26 13:22         ` Nicolas Goaziou

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).