mirror of
https://github.com/python/cpython.git
synced 2025-07-30 14:44:10 +00:00
[3.13] gh-127217: Fix pathname2url() for paths starting with multiple slashes on Posix (GH-127218) (GH-127230)
(cherry picked from commit 97b2ceaaaf
)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
4cba0e66c2
commit
c711deb803
3 changed files with 9 additions and 0 deletions
|
@ -1556,6 +1556,9 @@ class Pathname_Tests(unittest.TestCase):
|
||||||
fn = urllib.request.pathname2url
|
fn = urllib.request.pathname2url
|
||||||
self.assertEqual(fn('/'), '/')
|
self.assertEqual(fn('/'), '/')
|
||||||
self.assertEqual(fn('/a/b.c'), '/a/b.c')
|
self.assertEqual(fn('/a/b.c'), '/a/b.c')
|
||||||
|
self.assertEqual(fn('//a/b.c'), '////a/b.c')
|
||||||
|
self.assertEqual(fn('///a/b.c'), '/////a/b.c')
|
||||||
|
self.assertEqual(fn('////a/b.c'), '//////a/b.c')
|
||||||
self.assertEqual(fn('/a/b%#c'), '/a/b%25%23c')
|
self.assertEqual(fn('/a/b%#c'), '/a/b%25%23c')
|
||||||
|
|
||||||
@unittest.skipUnless(os_helper.FS_NONASCII, 'need os_helper.FS_NONASCII')
|
@unittest.skipUnless(os_helper.FS_NONASCII, 'need os_helper.FS_NONASCII')
|
||||||
|
|
|
@ -1670,6 +1670,10 @@ else:
|
||||||
def pathname2url(pathname):
|
def pathname2url(pathname):
|
||||||
"""OS-specific conversion from a file system path to a relative URL
|
"""OS-specific conversion from a file system path to a relative URL
|
||||||
of the 'file' scheme; not recommended for general use."""
|
of the 'file' scheme; not recommended for general use."""
|
||||||
|
if pathname[:2] == '//':
|
||||||
|
# Add explicitly empty authority to avoid interpreting the path
|
||||||
|
# as authority.
|
||||||
|
pathname = '//' + pathname
|
||||||
encoding = sys.getfilesystemencoding()
|
encoding = sys.getfilesystemencoding()
|
||||||
errors = sys.getfilesystemencodeerrors()
|
errors = sys.getfilesystemencodeerrors()
|
||||||
return quote(pathname, encoding=encoding, errors=errors)
|
return quote(pathname, encoding=encoding, errors=errors)
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
Fix :func:`urllib.request.pathname2url` for paths starting with multiple
|
||||||
|
slashes on Posix.
|
Loading…
Add table
Add a link
Reference in a new issue