summaryrefslogtreecommitdiffstats
path: root/Lib/plat-mac
diff options
context:
space:
mode:
authorJust van Rossum <just@letterror.com>2004-11-12 09:36:12 (GMT)
committerJust van Rossum <just@letterror.com>2004-11-12 09:36:12 (GMT)
commit2dae7646c30fcb347c093632a4df18292e246a1a (patch)
treeafb759bbc4f8f928ea8c2873ea9f50d6c94f5981 /Lib/plat-mac
parent48ecaccf9e2abd230b5745edc829118a1c526b64 (diff)
downloadcpython-2dae7646c30fcb347c093632a4df18292e246a1a.zip
cpython-2dae7646c30fcb347c093632a4df18292e246a1a.tar.gz
cpython-2dae7646c30fcb347c093632a4df18292e246a1a.tar.bz2
On second thought: "Errors should never pass silently", so barf when a
string contains control chars that are illegal for XML
Diffstat (limited to 'Lib/plat-mac')
-rw-r--r--Lib/plat-mac/plistlib.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/Lib/plat-mac/plistlib.py b/Lib/plat-mac/plistlib.py
index f73214d..49bd556 100644
--- a/Lib/plat-mac/plistlib.py
+++ b/Lib/plat-mac/plistlib.py
@@ -200,18 +200,21 @@ def _dateToString(d):
)
-# Regex to strip all control chars, but for \t \n and \r
-_controlStripper = re.compile(
+# Regex to find any control chars, except for \t \n and \r
+_controlCharPat = re.compile(
r"[\x00\x01\x02\x03\x04\x05\x06\x07\x08\x0b\x0c\x0e\x0f"
r"\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f]")
def _escapeAndEncode(text):
+ m = _controlCharPat.search(text)
+ if m is not None:
+ raise ValueError("strings can't contains control characters; "
+ "use plistlib.Data instead")
text = text.replace("\r\n", "\n") # convert DOS line endings
text = text.replace("\r", "\n") # convert Mac line endings
text = text.replace("&", "&amp;") # escape '&'
text = text.replace("<", "&lt;") # escape '<'
text = text.replace(">", "&gt;") # escape '>'
- text = _controlStripper.sub("?", text) # replace control chars with '?'
return text.encode("utf-8") # encode as UTF-8