Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-127236: pathname2url(): generate RFC 1738 URL for absolute POSIX path #127194

Merged
merged 4 commits into from
Nov 25, 2024

Conversation

barneygale
Copy link
Contributor

@barneygale barneygale commented Nov 23, 2024

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.

See #127125 for a related clarification to the docs.


📚 Documentation preview 📚: https://cpython-previews--127194.org.readthedocs.build/

… POSIX paths

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
pythonGH-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.
@barneygale barneygale changed the title GH-126148: pathname2url(): add authority section for absolute POSIX paths GH-126148: pathname2url(): add authority for absolute POSIX paths Nov 23, 2024
@barneygale barneygale changed the title GH-126148: pathname2url(): add authority for absolute POSIX paths GH-125866: pathname2url(): add authority for absolute POSIX paths Nov 23, 2024
@barneygale barneygale marked this pull request as ready for review November 24, 2024 17:41
@barneygale barneygale changed the title GH-125866: pathname2url(): add authority for absolute POSIX paths GH-127236: pathname2url(): add authority for absolute POSIX paths Nov 24, 2024
@barneygale barneygale changed the title GH-127236: pathname2url(): add authority for absolute POSIX paths GH-127236: pathname2url(): RFC 1738 URL for absolute POSIX path Nov 24, 2024
@barneygale barneygale changed the title GH-127236: pathname2url(): RFC 1738 URL for absolute POSIX path GH-127236: pathname2url(): generate RFC 1738 URL for absolute POSIX path Nov 24, 2024
Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but could you somewhere make a difference between adding // for path starting with / and // more explicit? It is necessary in the latter case, but cosmetic in the former case.

If RFC 8089 support will become more widespread and browsers and other programs will start normalizing the file: URI to a single flash, this change can be reverted, but the case with double slash should still be handled specially.

@barneygale
Copy link
Contributor Author

Thanks v much Serhiy - I've adjusted the code comment to explain the difference between / and //-prefixed paths.

@barneygale barneygale enabled auto-merge (squash) November 25, 2024 19:39
@barneygale barneygale merged commit 5bb059f into python:main Nov 25, 2024
37 checks passed
@bedevere-bot
Copy link

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot x86-64 MacOS Intel NoGIL 3.x has failed when building commit 5bb059f.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1258/builds/3419) and take a look at the build logs.
  4. Check if the failure is related to this commit (5bb059f) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1258/builds/3419

Failed tests:

  • test_threading

Failed subtests:

  • test_start_new_thread_failed - test.test_threading.ThreadTests.test_start_new_thread_failed
  • test_dump_traceback_threads - test.test_faulthandler.FaultHandlerTests.test_dump_traceback_threads

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "/Users/ec2-user/buildbot/buildarea/3.x.itamaro-macos-intel-aws.nogil/build/Lib/test/test_threading.py", line 1205, in test_start_new_thread_failed
    self.assertEqual(out, b'ok')
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^
AssertionError: b"skip\nshouldn't be printed" != b'ok'


Traceback (most recent call last):
  File "/Users/ec2-user/buildbot/buildarea/3.x.itamaro-macos-intel-aws.nogil/build/Lib/test/test_faulthandler.py", line 596, in test_dump_traceback_threads
    self.check_dump_traceback_threads(None)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
  File "/Users/ec2-user/buildbot/buildarea/3.x.itamaro-macos-intel-aws.nogil/build/Lib/test/test_faulthandler.py", line 592, in check_dump_traceback_threads
    self.assertRegex(output, regex)
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
AssertionError: Regex didn't match: '^Thread 0x[0-9a-f]+ \\(most recent call first\\):\n(?:  File ".*threading.py", line [0-9]+ in [_a-z]+\n){1,3}  File "<string>", line (?:22|23) in run\n  File ".*threading.py", line [0-9]+ in _bootstrap_inner\n  File ".*threading.py", line [0-9]+ in _bootstrap\n\nCurrent thread 0x[0-9a-f]+ \\(most recent call first\\):\n  File "<string>", line 10 in dump\n  File "<string>", line 28 in <module>$' not found in 'Thread 0x000070000d520000 (most recent call first):\n  File "/Users/ec2-user/buildbot/buildarea/3.x.itamaro-macos-intel-aws.nogil/build/Lib/threading.py"'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants