diff --git a/translate/storage/dtd.py b/translate/storage/dtd.py index feba993d80..3d303938a6 100644 --- a/translate/storage/dtd.py +++ b/translate/storage/dtd.py @@ -57,6 +57,8 @@ def quotefordtd(source): + if '%' in source: + source = source.replace("%", "") if '"' in source: if "'" in source: return "'" + source.replace("'", ''') + "'" @@ -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 diff --git a/translate/storage/test_dtd.py b/translate/storage/test_dtd.py index f60bda1e7f..7f878519e8 100644 --- a/translate/storage/test_dtd.py +++ b/translate/storage/test_dtd.py @@ -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"""