Skip to content

Commit 7c6f67a

Browse files
committed
Html escape traceback text in
1 parent cd0a957 commit 7c6f67a

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ CHANGES
66

77
- Add `aiohttp.web.StreamResponse.started` property #213
88

9+
- Html escape traceback text in `ServerHttpProtocol.handle_error`
10+
911

1012
0.13.0 (12-29-2014)
1113
-------------------

aiohttp/server.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import traceback
99
import socket
1010

11+
from html import escape as html_escape
12+
1113
import aiohttp
1214
from aiohttp import errors, streams, helpers
1315
from aiohttp.log import server_logger, access_logger
@@ -299,6 +301,7 @@ def handle_error(self, status=500,
299301
if self.debug and exc is not None:
300302
try:
301303
tb = traceback.format_exc()
304+
tb = html_escape(tb)
302305
msg += '<br><h2>Traceback:</h2>\n<pre>{}</pre>'.format(tb)
303306
except:
304307
pass

tests/test_http_server.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import unittest
66
import unittest.mock
77

8+
from html import escape
9+
810
from aiohttp import server
911
from aiohttp import errors
1012
from aiohttp import test_utils
@@ -260,9 +262,8 @@ def test_handle_error__utf(self):
260262
[c[1][0] for c in list(srv.writer.write.mock_calls)])
261263
self.assertIn(b'HTTP/1.1 500 Internal Server Error', content)
262264
self.assertIn(b'CONTENT-TYPE: text/html; charset=utf-8', content)
263-
self.assertIn(
264-
"raise RuntimeError('что-то пошло не так')".encode('utf-8'),
265-
content)
265+
pattern = escape("raise RuntimeError('что-то пошло не так')")
266+
self.assertIn(pattern.encode('utf-8'), content)
266267
self.assertFalse(srv._keep_alive)
267268

268269
srv.logger.exception.assert_called_with("Error handling request")

0 commit comments

Comments
 (0)