diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-10-08 21:08:48 +0300 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-10-08 21:08:48 +0300 |
commit | 9d67ec51a65af6408887041d8e841c1bf7d046b7 (patch) | |
tree | c3201ce7b6a3128cb8216a6e04ad208d4d9428d9 /Lib/html/__init__.py | |
parent | c3a0b4fef5f33c776857fe336932d163cd56815d (diff) | |
parent | 3cf0676c2d969a7c795c3ccf152e2dd77008ee14 (diff) | |
download | cpython-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__.py | 13 |
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('&'): '&', ord('<'): '<', ord('>'): '>'} -_escape_map_full = {ord('&'): '&', ord('<'): '<', ord('>'): '>', - ord('"'): '"', ord('\''): '''} - # 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("&", "&") # Must be done first! + s = s.replace("<", "<") + s = s.replace(">", ">") if quote: - return s.translate(_escape_map_full) - return s.translate(_escape_map) + s = s.replace('"', """) + s = s.replace('\'', "'") + return s |