Skip to content

Commit

Permalink
% is not valid in a dtd so broken translation where a translator adde…
Browse files Browse the repository at this point in the history
…d %s should be converted to an entity i.e. &translate#25; for percent.

svn path=/src/trunk/; revision=18091
  • Loading branch information
dwaynebailey committed Mar 18, 2012
1 parent 8570f64 commit 191c30d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
3 changes: 3 additions & 0 deletions translate/storage/dtd.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@


def quotefordtd(source):
if '%' in source:
source = source.replace("%", "")
if '"' in source:
if "'" in source:
return "'" + source.replace("'", ''') + "'"
Expand All @@ -75,6 +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("", "%")
# 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
9 changes: 9 additions & 0 deletions translate/storage/test_dtd.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ def test_roundtrip_quoting():
assert special == unquoted_special


def test_quotefordtd():
"""Test quoting and unqouting dtd definitions"""
def tester(raw_original, dtd_ready_result):
#print dtd.quotefordtd(raw_original)
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"')

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

Expand Down

0 comments on commit 191c30d

Please sign in to comment.