| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -750,7 +750,7 @@ def send_head(self): | |||
| 750 | 750 | f = None | |
| 751 | 751 | if os.path.isdir(path): | |
| 752 | 752 | parts = urllib.parse.urlsplit(self.path) | |
| 753 | - if not parts.path.endswith('/'): | ||
| 753 | + if not parts.path.endswith(('/', '%2f', '%2F')): | ||
| 754 | 754 | # redirect browser - doing basically what apache does | |
| 755 | 755 | self.send_response(HTTPStatus.MOVED_PERMANENTLY) | |
| 756 | 756 | new_parts = (parts[0], parts[1], parts[2] + '/', | |
@@ -890,14 +890,14 @@ def translate_path(self, path): | |||
| 890 | 890 | ||
| 891 | 891 | """ | |
| 892 | 892 | # abandon query parameters | |
| 893 | - path = path.split('?',1)[0] | ||
| 894 | - path = path.split('#',1)[0] | ||
| 893 | + path = path.split('#', 1)[0] | ||
| 894 | + path = path.split('?', 1)[0] | ||
| 895 | 895 | # Don't forget explicit trailing slash when normalizing. Issue17324 | |
| 896 | - trailing_slash = path.rstrip().endswith('/') | ||
| 897 | 896 | try: | |
| 898 | 897 | path = urllib.parse.unquote(path, errors='surrogatepass') | |
| 899 | 898 | except UnicodeDecodeError: | |
| 900 | 899 | path = urllib.parse.unquote(path) | |
| 900 | + trailing_slash = path.endswith('/') | ||
| 901 | 901 | path = posixpath.normpath(path) | |
| 902 | 902 | words = path.split('/') | |
| 903 | 903 | words = filter(None, words) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -692,10 +692,19 @@ def test_get(self): | |||
| 692 | 692 | # check for trailing "/" which should return 404. See Issue17324 | |
| 693 | 693 | response = self.request(self.base_url + '/test/') | |
| 694 | 694 | self.check_status_and_reason(response, HTTPStatus.NOT_FOUND) | |
| 695 | + response = self.request(self.base_url + '/test%2f') | ||
| 696 | + self.check_status_and_reason(response, HTTPStatus.NOT_FOUND) | ||
| 697 | + response = self.request(self.base_url + '/test%2F') | ||
| 698 | + self.check_status_and_reason(response, HTTPStatus.NOT_FOUND) | ||
| 695 | 699 | response = self.request(self.base_url + '/') | |
| 696 | 700 | self.check_status_and_reason(response, HTTPStatus.OK) | |
| 701 | + response = self.request(self.base_url + '%2f') | ||
| 702 | + self.check_status_and_reason(response, HTTPStatus.OK) | ||
| 703 | + response = self.request(self.base_url + '%2F') | ||
| 704 | + self.check_status_and_reason(response, HTTPStatus.OK) | ||
| 697 | 705 | response = self.request(self.base_url) | |
| 698 | 706 | self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY) | |
| 707 | + self.assertEqual(response.getheader("Location"), self.base_url + "/") | ||
| 699 | 708 | self.assertEqual(response.getheader("Content-Length"), "0") | |
| 700 | 709 | response = self.request(self.base_url + '/?hi=2') | |
| 701 | 710 | self.check_status_and_reason(response, HTTPStatus.OK) | |
@@ -801,6 +810,8 @@ def test_path_without_leading_slash(self): | |||
| 801 | 810 | self.check_status_and_reason(response, HTTPStatus.OK) | |
| 802 | 811 | response = self.request(self.tempdir_name) | |
| 803 | 812 | self.check_status_and_reason(response, HTTPStatus.MOVED_PERMANENTLY) | |
| 813 | + self.assertEqual(response.getheader("Location"), | ||
| 814 | + self.tempdir_name + "/") | ||
| 804 | 815 | response = self.request(self.tempdir_name + '/?hi=2') | |
| 805 | 816 | self.check_status_and_reason(response, HTTPStatus.OK) | |
| 806 | 817 | response = self.request(self.tempdir_name + '?hi=1') | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,2 @@ | |||
| 1 | + Fix handling paths that end with a percent-encoded slash (``%2f`` or | ||
| 2 | + ``%2F``) in :class:`http.server.SimpleHTTPRequestHandler`. | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments