Skip to content

Commit

Permalink
% is 25 hex not decimal. Also output a better error message from the …
Browse files Browse the repository at this point in the history
…DTD parser to highlight the error.

svn path=/src/trunk/; revision=18092
  • Loading branch information
dwaynebailey committed Mar 19, 2012
1 parent 191c30d commit 2abe68d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions translate/storage/dtd.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@

def quotefordtd(source):
if '%' in source:
source = source.replace("%", "")
source = source.replace("%", "%")
if '"' in source:
if "'" in source:
return "'" + source.replace("'", ''') + "'"
Expand All @@ -77,7 +77,7 @@ def unquotefromdtd(source):
extracted, quotefinished = quote.extractwithoutquotes(source, quotechar, quotechar, allowreentry=False)
if quotechar == "'" and "'" in extracted:
extracted = extracted.replace("'", "'")
extracted = extracted.replace("", "%")
extracted = extracted.replace("%", "%")
# the quote characters should be the first and last characters in the string
# of course there could also be quote characters within the string; not handled here
return extracted
Expand Down Expand Up @@ -471,6 +471,7 @@ def _valid_store(self):
try:
# #expand is a Mozilla hack and are removed as they are not valid in DTDs
dtd = etree.DTD(StringIO.StringIO(re.sub("#expand", "", self.getoutput())))
except etree.DTDParseError:
except etree.DTDParseError as e:
warnings.warn("DTD parse error: %s" % e.error_log)
return False
return True
2 changes: 1 addition & 1 deletion translate/storage/test_dtd.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def tester(raw_original, dtd_ready_result):
assert dtd.quotefordtd(raw_original) == dtd_ready_result
#print dtd.unquotefromdtd(dtd_ready_result)
assert dtd.unquotefromdtd(dtd_ready_result) == raw_original
tester("Unintentional variable %S", '"Unintentional variable S"')
tester("Unintentional variable %S", '"Unintentional variable %S"')

def test_removeinvalidamp(recwarn):
"""tests the the removeinvalidamps function"""
Expand Down

0 comments on commit 2abe68d

Please sign in to comment.