diff options
author | Dong-hee Na <donghee.na92@gmail.com> | 2019-09-27 19:59:37 (GMT) |
---|---|---|
committer | Victor Stinner <vstinner@redhat.com> | 2019-09-27 19:59:37 (GMT) |
commit | e8650a4f8c7fb76f570d4ca9c1fbe44e91c8dfaa (patch) | |
tree | 21492197b7eca061db3cc120a1fdadc686910e56 /Lib | |
parent | dd6117c6d7859fee57751593cd56f0862131de8b (diff) | |
download | cpython-e8650a4f8c7fb76f570d4ca9c1fbe44e91c8dfaa.zip cpython-e8650a4f8c7fb76f570d4ca9c1fbe44e91c8dfaa.tar.gz cpython-e8650a4f8c7fb76f570d4ca9c1fbe44e91c8dfaa.tar.bz2 |
bpo-38243, xmlrpc.server: Escape the server_title (GH-16373)
Escape the server title of xmlrpc.server.DocXMLRPCServer
when rendering the document page as HTML.
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_docxmlrpc.py | 16 | ||||
-rw-r--r-- | Lib/xmlrpc/server.py | 3 |
2 files changed, 18 insertions, 1 deletions
diff --git a/Lib/test/test_docxmlrpc.py b/Lib/test/test_docxmlrpc.py index 116e626..7d3e30c 100644 --- a/Lib/test/test_docxmlrpc.py +++ b/Lib/test/test_docxmlrpc.py @@ -1,5 +1,6 @@ from xmlrpc.server import DocXMLRPCServer import http.client +import re import sys import threading import unittest @@ -192,6 +193,21 @@ class DocXMLRPCHTTPGETServer(unittest.TestCase): b'method_annotation</strong></a>(x: bytes)</dt></dl>'), response.read()) + def test_server_title_escape(self): + # bpo-38243: Ensure that the server title and documentation + # are escaped for HTML. + self.serv.set_server_title('test_title<script>') + self.serv.set_server_documentation('test_documentation<script>') + self.assertEqual('test_title<script>', self.serv.server_title) + self.assertEqual('test_documentation<script>', + self.serv.server_documentation) + + generated = self.serv.generate_html_documentation() + title = re.search(r'<title>(.+?)</title>', generated).group() + documentation = re.search(r'<p><tt>(.+?)</tt></p>', generated).group() + self.assertEqual('<title>Python: test_title<script></title>', title) + self.assertEqual('<p><tt>test_documentation<script></tt></p>', documentation) + if __name__ == '__main__': unittest.main() diff --git a/Lib/xmlrpc/server.py b/Lib/xmlrpc/server.py index f1c467e..32aba4d 100644 --- a/Lib/xmlrpc/server.py +++ b/Lib/xmlrpc/server.py @@ -108,6 +108,7 @@ from xmlrpc.client import Fault, dumps, loads, gzip_encode, gzip_decode from http.server import BaseHTTPRequestHandler from functools import partial from inspect import signature +import html import http.server import socketserver import sys @@ -894,7 +895,7 @@ class XMLRPCDocGenerator: methods ) - return documenter.page(self.server_title, documentation) + return documenter.page(html.escape(self.server_title), documentation) class DocXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): """XML-RPC and documentation request handler class. |