Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit821a87e

Browse files
[3.13]gh-133889: Only show the path of the URL in the SimpleHTTPRequestHandler page (GH-134135) (GH-134191)
The query and fragment are ambiguous and not used.(cherry picked from commit5cbc8c6)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent018ec63 commit821a87e

File tree

3 files changed

+15
-8
lines changed

3 files changed

+15
-8
lines changed

‎Lib/http/server.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -791,11 +791,14 @@ def list_directory(self, path):
791791
returnNone
792792
list.sort(key=lambdaa:a.lower())
793793
r= []
794+
displaypath=self.path
795+
displaypath=displaypath.split('#',1)[0]
796+
displaypath=displaypath.split('?',1)[0]
794797
try:
795-
displaypath=urllib.parse.unquote(self.path,
798+
displaypath=urllib.parse.unquote(displaypath,
796799
errors='surrogatepass')
797800
exceptUnicodeDecodeError:
798-
displaypath=urllib.parse.unquote(self.path)
801+
displaypath=urllib.parse.unquote(displaypath)
799802
displaypath=html.escape(displaypath,quote=False)
800803
enc=sys.getfilesystemencoding()
801804
title=f'Directory listing for{displaypath}'

‎Lib/test/test_httpservers.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -517,13 +517,14 @@ def test_list_dir_escape_filename(self):
517517
self.check_list_dir_filename(filename)
518518
os_helper.unlink(os.path.join(self.tempdir,filename))
519519

520-
deftest_undecodable_parameter(self):
521-
# sanity check using a valid parameter
520+
deftest_list_dir_with_query_and_fragment(self):
521+
prefix=f'listing for{self.base_url}/</'.encode('latin1')
522+
response=self.request(self.base_url+'/#123').read()
523+
self.assertIn(prefix+b'title>',response)
524+
self.assertIn(prefix+b'h1>',response)
522525
response=self.request(self.base_url+'/?x=123').read()
523-
self.assertRegex(response,rf'listing for{self.base_url}/\?x=123'.encode('latin1'))
524-
# now the bogus encoding
525-
response=self.request(self.base_url+'/?x=%bb').read()
526-
self.assertRegex(response,rf'listing for{self.base_url}/\?x=\xef\xbf\xbd'.encode('latin1'))
526+
self.assertIn(prefix+b'title>',response)
527+
self.assertIn(prefix+b'h1>',response)
527528

528529
deftest_get_dir_redirect_location_domain_injection_bug(self):
529530
"""Ensure //evil.co/..%2f../../X does not put //evil.co/ in Location.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The generated directory listing page in
2+
:class:`http.server.SimpleHTTPRequestHandler` now only shows the decoded
3+
path component of the requested URL, and not the query and fragment.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp