[PATCH v2 19/20] nmbug-status: Escape &, <, and > in HTML display data
W. Trevor King
wking at tremily.us
Mon Feb 10 10:40:40 PST 2014
'message-id' and 'from' now have sensitive characters escaped using
xml.sax.saxutils.escape [1]. The 'subject' data was already being
converted to a link into Gmane; I've escape()d that too, so it doesn't
need to be handled ain the same block as 'message-id' and 'from'.
This prevents broken HTML by if subjects etc. contain characters that
would otherwise be interpreted as HTML markup.
[1]: http://docs.python.org/3/library/xml.sax.utils.html#xml.sax.saxutils.escape
---
devel/nmbug/nmbug-status | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/devel/nmbug/nmbug-status b/devel/nmbug/nmbug-status
index 1f0873a..7209dd1 100755
--- a/devel/nmbug/nmbug-status
+++ b/devel/nmbug/nmbug-status
@@ -24,6 +24,7 @@ import os
import re
import sys
import subprocess
+import xml.sax.saxutils
_ENCODING = locale.getpreferredencoding() or sys.getdefaultencoding()
@@ -229,11 +230,14 @@ class HtmlPage (Page):
if 'subject' in display_data and 'message-id' in display_data:
d = {
'message-id': quote(display_data['message-id']),
- 'subject': display_data['subject'],
+ 'subject': xml.sax.saxutils.escape(display_data['subject']),
}
display_data['subject'] = (
'<a href="http://mid.gmane.org/{message-id}">{subject}</a>'
).format(**d)
+ for key in ['message-id', 'from']:
+ if key in display_data:
+ display_data[key] = xml.sax.saxutils.escape(display_data[key])
return (running_data, display_data)
def _slug(self, string):
--
1.8.5.2.8.g0f6c0d1
More information about the notmuch
mailing list