Escape content when generating DTD for fieldmapper
authorDan Scott <dscott@laurentian.ca>
Thu, 16 Feb 2012 17:49:54 +0000 (12:49 -0500)
committerThomas Berezansky <tsbere@mvlc.org>
Thu, 16 Feb 2012 18:56:04 +0000 (13:56 -0500)
Noticed by Thomas Berezansky, if a translation in a PO or POT file
contains an unescaped left angle bracket, a DTD will be generated that
contains the unescaped left angle bracket - and that isn't valid.

Signed-off-by: Dan Scott <dscott@laurentian.ca>
Signed-off-by: Thomas Berezansky <tsbere@mvlc.org>

build/i18n/scripts/fieldmapper.py
build/i18n/tests/data/testidl.ent
build/i18n/tests/data/testidl.po

index 385fce5..51e5ba5 100755 (executable)
@@ -24,6 +24,7 @@ import polib
 import sys
 import xml.sax
 import xml.sax.handler
+import xml.sax.saxutils
 
 class IDL(basel10n.BaseL10N):
     """
@@ -64,14 +65,14 @@ class IDL(basel10n.BaseL10N):
         """
         Creates an entity definition file based on a translated PO file.
         """
-        entity = '<!ENTITY %s "%s">'
+        entity = '<!ENTITY %s %s>'
         for entry in self.pot:
             for name in entry.occurrences:
+                entdef = xml.sax.saxutils.quoteattr(entry.msgstr)
                 if entry.msgstr == '':
                     # No translation available; use the en-US definition
-                    self.definitions.append(entity % (name[0], entry.msgid))
-                else:
-                    self.definitions.append(entity % (name[0], entry.msgstr))
+                    entdef = xml.sax.saxutils.quoteattr(entry.msgid)
+                self.definitions.append(entity % (name[0], entdef))
 
 class IDLHandler(xml.sax.handler.ContentHandler):
     """
index d1cfb57..effd5c5 100644 (file)
@@ -11,7 +11,7 @@
 <!ENTITY class.auoi.label "venenatis, mi nisl">
 <!ENTITY field.rodcirc.recurring_fine_rule.label "suscipit sapien, eu sollicitudin">
 <!ENTITY field.rodcirc.duration_rule.label "neque dolor a nulla">
-<!ENTITY field.auoi.id.label "Phasellus aliquam vulputate justo">
+<!ENTITY field.auoi.id.label 'Phasellus " aliquam vulputate justo'>
 <!ENTITY field.rodcirc.payment_total.label "Proin augue libero">
 <!ENTITY field.rodcirc.phone_renewal.label "hendrerit pretium">
 <!ENTITY field.rodcirc.circ_lib.label "rutrum pretium">
@@ -37,6 +37,6 @@
 <!ENTITY field.auoi.opt_in_ts.label "sapien id velit nonummy">
 <!ENTITY field.rodcirc.desk_renewal.label "congue, neque">
 <!ENTITY field.rodcirc.target_copy.label "ut ullamcorper faucibus">
-<!ENTITY field.rodcirc.renewal_remaining.label "diam felis">
+<!ENTITY field.rodcirc.renewal_remaining.label "diam felis&lt;">
 <!ENTITY field.aws.owning_lib.label "Owning Library">
 <!ENTITY field.rodcirc.id.label "pulvinar augue">
index 744cff4..ec4605b 100644 (file)
@@ -65,7 +65,7 @@ msgstr "neque dolor a nulla"
 
 #: field.auoi.id.label:25
 msgid "Opt-in ID"
-msgstr "Phasellus aliquam vulputate justo"
+msgstr "Phasellus \" aliquam vulputate justo"
 
 #: field.rodcirc.payment_total.label:86
 msgid "Payment Totals"
@@ -165,7 +165,7 @@ msgstr "ut ullamcorper faucibus"
 
 #: field.rodcirc.renewal_remaining.label:74
 msgid "Remaining Renewals"
-msgstr "diam felis"
+msgstr "diam felis<"
 
 #: field.aws.owning_lib.label:46
 msgid "Owning Library"