Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
cpython
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Batuhan Osman TASKAYA
cpython
Commits
41a08e55
Kaydet (Commit)
41a08e55
authored
Agu 17, 2014
tarafından
Serhiy Storchaka
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Sade Fark
Issue #22165: SimpleHTTPRequestHandler now supports undecodable file names.
üst
f9e227e5
cb5bc408
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
36 additions
and
4 deletions
+36
-4
server.py
Lib/http/server.py
+15
-4
test_httpservers.py
Lib/test/test_httpservers.py
+19
-0
NEWS
Misc/NEWS
+2
-0
No files found.
Lib/http/server.py
Dosyayı görüntüle @
41a08e55
...
...
@@ -747,7 +747,12 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
return
None
list
.
sort
(
key
=
lambda
a
:
a
.
lower
())
r
=
[]
displaypath
=
html
.
escape
(
urllib
.
parse
.
unquote
(
self
.
path
))
try
:
displaypath
=
urllib
.
parse
.
unquote
(
self
.
path
,
errors
=
'surrogatepass'
)
except
UnicodeDecodeError
:
displaypath
=
urllib
.
parse
.
unquote
(
path
)
displaypath
=
html
.
escape
(
displaypath
)
enc
=
sys
.
getfilesystemencoding
()
title
=
'Directory listing for
%
s'
%
displaypath
r
.
append
(
'<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" '
...
...
@@ -769,9 +774,11 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
displayname
=
name
+
"@"
# Note: a link to a directory displays with @ and links with /
r
.
append
(
'<li><a href="
%
s">
%
s</a></li>'
%
(
urllib
.
parse
.
quote
(
linkname
),
html
.
escape
(
displayname
)))
%
(
urllib
.
parse
.
quote
(
linkname
,
errors
=
'surrogatepass'
),
html
.
escape
(
displayname
)))
r
.
append
(
'</ul>
\n
<hr>
\n
</body>
\n
</html>
\n
'
)
encoded
=
'
\n
'
.
join
(
r
)
.
encode
(
enc
)
encoded
=
'
\n
'
.
join
(
r
)
.
encode
(
enc
,
'surrogateescape'
)
f
=
io
.
BytesIO
()
f
.
write
(
encoded
)
f
.
seek
(
0
)
...
...
@@ -794,7 +801,11 @@ class SimpleHTTPRequestHandler(BaseHTTPRequestHandler):
path
=
path
.
split
(
'#'
,
1
)[
0
]
# Don't forget explicit trailing slash when normalizing. Issue17324
trailing_slash
=
path
.
rstrip
()
.
endswith
(
'/'
)
path
=
posixpath
.
normpath
(
urllib
.
parse
.
unquote
(
path
))
try
:
path
=
urllib
.
parse
.
unquote
(
path
,
errors
=
'surrogatepass'
)
except
UnicodeDecodeError
:
path
=
urllib
.
parse
.
unquote
(
path
)
path
=
posixpath
.
normpath
(
path
)
words
=
path
.
split
(
'/'
)
words
=
filter
(
None
,
words
)
path
=
os
.
getcwd
()
...
...
Lib/test/test_httpservers.py
Dosyayı görüntüle @
41a08e55
...
...
@@ -14,6 +14,7 @@ import re
import
base64
import
shutil
import
urllib.parse
import
html
import
http.client
import
tempfile
from
io
import
BytesIO
...
...
@@ -266,6 +267,24 @@ class SimpleHTTPServerTestCase(BaseTestCase):
self
.
assertIsNotNone
(
response
.
reason
)
if
data
:
self
.
assertEqual
(
data
,
body
)
return
body
@unittest.skipUnless
(
support
.
TESTFN_UNDECODABLE
,
'need support.TESTFN_UNDECODABLE'
)
def
test_undecodable_filename
(
self
):
filename
=
os
.
fsdecode
(
support
.
TESTFN_UNDECODABLE
)
+
'.txt'
with
open
(
os
.
path
.
join
(
self
.
tempdir
,
filename
),
'wb'
)
as
f
:
f
.
write
(
support
.
TESTFN_UNDECODABLE
)
response
=
self
.
request
(
self
.
tempdir_name
+
'/'
)
body
=
self
.
check_status_and_reason
(
response
,
200
)
quotedname
=
urllib
.
parse
.
quote
(
filename
,
errors
=
'surrogatepass'
)
self
.
assertIn
((
'href="
%
s"'
%
quotedname
)
.
encode
(
'utf-8'
,
'surrogateescape'
),
body
)
self
.
assertIn
((
'>
%
s<'
%
html
.
escape
(
filename
))
.
encode
(
'utf-8'
,
'surrogateescape'
),
body
)
response
=
self
.
request
(
self
.
tempdir_name
+
'/'
+
quotedname
)
self
.
check_status_and_reason
(
response
,
200
,
data
=
support
.
TESTFN_UNDECODABLE
)
def
test_get
(
self
):
#constructs the path relative to the root directory of the HTTPServer
...
...
Misc/NEWS
Dosyayı görüntüle @
41a08e55
...
...
@@ -118,6 +118,8 @@ Core and Builtins
Library
-------
-
Issue
#
22165
:
SimpleHTTPRequestHandler
now
supports
undecodable
file
names
.
-
Issue
#
15381
:
Optimized
line
reading
in
io
.
BytesIO
.
-
Issue
#
20729
:
Restored
the
use
of
lazy
iterkeys
()/
itervalues
()/
iteritems
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment