Removed
Link Here
|
1 |
https://github.com/cherrypy/cherrypy/commit/c65dc279d1d8 |
2 |
|
3 |
--- cherrypy/_cpcompat.py.orig 2016-05-11 00:35:35 UTC |
4 |
+++ cherrypy/_cpcompat.py |
5 |
@@ -357,3 +357,19 @@ class SetDaemonProperty: |
6 |
|
7 |
if sys.version_info < (2, 6): |
8 |
daemon = property(__get_daemon, __set_daemon) |
9 |
+ |
10 |
+# html module come in 3.2 version |
11 |
+try: |
12 |
+ from html import escape |
13 |
+except ImportError: |
14 |
+ from cgi import escape |
15 |
+ |
16 |
+# html module needed the argument quote=False because in cgi the default |
17 |
+# is False. With quote=True the results differ. |
18 |
+ |
19 |
+def escape_html(s, escape_quote=False): |
20 |
+ """Replace special characters "&", "<" and ">" to HTML-safe sequences. |
21 |
+ |
22 |
+ When escape_quote=True, escape (') and (") chars. |
23 |
+ """ |
24 |
+ return escape(s, quote=escape_quote) |
25 |
--- cherrypy/_cperror.py.orig 2016-05-11 00:35:35 UTC |
26 |
+++ cherrypy/_cperror.py |
27 |
@@ -115,9 +115,9 @@ Note that you have to explicitly set |
28 |
and not simply return an error message as a result. |
29 |
""" |
30 |
|
31 |
-from cgi import escape as _escape |
32 |
from sys import exc_info as _exc_info |
33 |
from traceback import format_exception as _format_exception |
34 |
+from cherrypy._cpcompat import escape_html |
35 |
from cherrypy._cpcompat import basestring, bytestr, iteritems, ntob |
36 |
from cherrypy._cpcompat import tonative, urljoin as _urljoin |
37 |
from cherrypy.lib import httputil as _httputil |
38 |
@@ -489,7 +489,7 @@ def get_error_page(status, **kwargs): |
39 |
if v is None: |
40 |
kwargs[k] = "" |
41 |
else: |
42 |
- kwargs[k] = _escape(kwargs[k]) |
43 |
+ kwargs[k] = escape_html(kwargs[k]) |
44 |
|
45 |
# Use a custom template or callable for the error page? |
46 |
pages = cherrypy.serving.request.error_page |
47 |
--- cherrypy/test/test_compat.py.orig 2016-05-11 00:35:35 UTC |
48 |
+++ cherrypy/test/test_compat.py |
49 |
@@ -17,3 +17,11 @@ class StringTester(unittest.TestCase): |
50 |
if compat.py3k: |
51 |
raise nose.SkipTest("Only useful on Python 2") |
52 |
self.assertRaises(Exception, compat.ntob, unicode('fight')) |
53 |
+ |
54 |
+ |
55 |
+class EscapeTester(unittest.TestCase): |
56 |
+ """Class to test escape_html function from _cpcompat.""" |
57 |
+ |
58 |
+ def test_escape_quote(self): |
59 |
+ """test_escape_quote - Verify the output for &<>"' chars.""" |
60 |
+ self.assertEqual("""xx&<>"aa'""", compat.escape_html("""xx&<>"aa'""")) |