File compatibility_w_Python_fix.patch of Package python-CherryPy.13436
From 6bb23991325f596023b8c87c76098870a7185df8 Mon Sep 17 00:00:00 2001
From: "Jason R. Coombs" <jaraco@jaraco.com>
Date: Sat, 21 Sep 2019 20:35:51 +0200
Subject: [PATCH 1/3] Rewrite the disallowed characters to only disallow
newlines, allowing null bytes. Fixes #1781.
---
cherrypy/test/test_static.py | 3 +++
1 file changed, 3 insertions(+)
--- a/cherrypy/test/test_static.py
+++ b/cherrypy/test/test_static.py
@@ -2,10 +2,18 @@
import contextlib
import io
import os
+import re
import sys
import platform
import tempfile
+import unittest.mock
+try:
+ import httplib
+except ImportError:
+ import http.client
+
+import six
from six import text_type as str
from six.moves import urllib
@@ -380,9 +388,24 @@ class StaticTest(helper.CPWebCase):
self.assertStatus(404)
self.assertInBody("I couldn't find that thing")
- def test_null_bytes(self):
- self.getPage('/static/\x00')
- self.assertStatus('404 Not Found')
+ if six.PY2:
+ @unittest.mock.patch(
+ 'httplib._contains_disallowed_url_pchar_re',
+ re.compile(r'[\n]'),
+ create=True,
+ )
+ def test_null_bytes(self):
+ self.getPage('/static/\x00')
+ self.assertStatus('404 Not Found')
+ elif six.PY3:
+ @unittest.mock.patch(
+ 'http.client._contains_disallowed_url_pchar_re',
+ re.compile(r'[\n]'),
+ create=True,
+ )
+ def test_null_bytes(self):
+ self.getPage('/static/\x00')
+ self.assertStatus('404 Not Found')
@staticmethod
@contextlib.contextmanager