summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_urllib.py
diff options
context:
space:
mode:
authorBarney Gale <barney.gale@gmail.com>2024-11-25 19:59:20 (GMT)
committerGitHub <noreply@github.com>2024-11-25 19:59:20 (GMT)
commit5bb059fe606983814a445e4dcf9e96fd7cb4951a (patch)
tree676161387dee7f7b757b947199db07f8b29da54f /Lib/test/test_urllib.py
parenta2ee89968299fc4f0da4b5a4165025b941213ba5 (diff)
downloadcpython-5bb059fe606983814a445e4dcf9e96fd7cb4951a.zip
cpython-5bb059fe606983814a445e4dcf9e96fd7cb4951a.tar.gz
cpython-5bb059fe606983814a445e4dcf9e96fd7cb4951a.tar.bz2
GH-127236: `pathname2url()`: generate RFC 1738 URL for absolute POSIX path (#127194)
When handed an absolute Windows path such as `C:\foo` or `//server/share`, the `urllib.request.pathname2url()` function returns a URL with an authority section, such as `///C:/foo` or `//server/share` (or before GH-126205, `////server/share`). Only the `file:` prefix is omitted. But when handed an absolute POSIX path such as `/etc/hosts`, or a Windows path of the same form (rooted but lacking a drive), the function returns a URL without an authority section, such as `/etc/hosts`. This patch corrects the discrepancy by adding a `//` prefix before drive-less, rooted paths when generating URLs.
Diffstat (limited to 'Lib/test/test_urllib.py')
-rw-r--r--Lib/test/test_urllib.py10
1 files changed, 5 insertions, 5 deletions
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index fe16bad..00e4699 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -1434,7 +1434,7 @@ class Pathname_Tests(unittest.TestCase):
self.assertEqual(fn('C:\\foo:bar'), '///C:/foo%3Abar')
self.assertEqual(fn('foo:bar'), 'foo%3Abar')
# No drive letter
- self.assertEqual(fn("\\folder\\test\\"), '/folder/test/')
+ self.assertEqual(fn("\\folder\\test\\"), '///folder/test/')
self.assertEqual(fn("\\\\folder\\test\\"), '//folder/test/')
self.assertEqual(fn("\\\\\\folder\\test\\"), '///folder/test/')
self.assertEqual(fn('\\\\some\\share\\'), '//some/share/')
@@ -1447,7 +1447,7 @@ class Pathname_Tests(unittest.TestCase):
self.assertEqual(fn('//?/unc/server/share/dir'), '//server/share/dir')
# Round-tripping
urls = ['///C:',
- '/folder/test/',
+ '///folder/test/',
'///C:/foo/bar/spam.foo']
for url in urls:
self.assertEqual(fn(urllib.request.url2pathname(url)), url)
@@ -1456,12 +1456,12 @@ class Pathname_Tests(unittest.TestCase):
'test specific to POSIX pathnames')
def test_pathname2url_posix(self):
fn = urllib.request.pathname2url
- self.assertEqual(fn('/'), '/')
- self.assertEqual(fn('/a/b.c'), '/a/b.c')
+ 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%25%23c')
+ self.assertEqual(fn('/a/b%#c'), '///a/b%25%23c')
@unittest.skipUnless(os_helper.FS_NONASCII, 'need os_helper.FS_NONASCII')
def test_pathname2url_nonascii(self):