summaryrefslogtreecommitdiff
path: root/Lib/html/__init__.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-10-08 21:08:48 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2013-10-08 21:08:48 +0300
commit9d67ec51a65af6408887041d8e841c1bf7d046b7 (patch)
treec3201ce7b6a3128cb8216a6e04ad208d4d9428d9 /Lib/html/__init__.py
parentc3a0b4fef5f33c776857fe336932d163cd56815d (diff)
parent3cf0676c2d969a7c795c3ccf152e2dd77008ee14 (diff)
downloadcpython-9d67ec51a65af6408887041d8e841c1bf7d046b7.tar.gz
Issue #18037: Do not escape '\u' and '\U' in raw strings.
Diffstat (limited to 'Lib/html/__init__.py')
-rw-r--r--Lib/html/__init__.py13
1 files changed, 6 insertions, 7 deletions
diff --git a/Lib/html/__init__.py b/Lib/html/__init__.py
index 02652ef73c..2ad167f16a 100644
--- a/Lib/html/__init__.py
+++ b/Lib/html/__init__.py
@@ -2,11 +2,6 @@
General functions for HTML manipulation.
"""
-
-_escape_map = {ord('&'): '&amp;', ord('<'): '&lt;', ord('>'): '&gt;'}
-_escape_map_full = {ord('&'): '&amp;', ord('<'): '&lt;', ord('>'): '&gt;',
- ord('"'): '&quot;', ord('\''): '&#x27;'}
-
# NB: this is a candidate for a bytes/string polymorphic interface
def escape(s, quote=True):
@@ -16,6 +11,10 @@ def escape(s, quote=True):
characters, both double quote (") and single quote (') characters are also
translated.
"""
+ s = s.replace("&", "&amp;") # Must be done first!
+ s = s.replace("<", "&lt;")
+ s = s.replace(">", "&gt;")
if quote:
- return s.translate(_escape_map_full)
- return s.translate(_escape_map)
+ s = s.replace('"', "&quot;")
+ s = s.replace('\'', "&#x27;")
+ return s