René's URL Explorer Experiment


Title: bpo-36305: Fixes to path handling and parsing in pathlib by kmaork · Pull Request #12361 · python/cpython · GitHub

Open Graph Title: bpo-36305: Fixes to path handling and parsing in pathlib by kmaork · Pull Request #12361 · python/cpython

X Title: bpo-36305: Fixes to path handling and parsing in pathlib by kmaork · Pull Request #12361 · python/cpython

Description: The bugs This PR fixes three bugs with path parsing in pathlib. The following examples show these bugs (when the cwd is C:\d): WindowsPath('C:a').absolute() should return WindowsPath('C:\\d\\a') but returns WindowsPath('C:a'). This is caused by flawed logic in the parse_parts method of the _Flavour class. WindowsPath('./b:a').absolute() should return WindowsPath('C:\\d\\b:a') but returns WindowsPath('b:a'). This is caused by the limited interface of parse_parts, and affects the Path.absolute, Path.expanduser and Path.__rtruediv__ methods. WindowsPath('./b:a').resolve() should return WindowsPath('C:\\d\\b:a') but returns WindowsPath('b:a'). This is caused by missing logic in the resolve method and in Path.__str__ The fixes To fix the first bug, I fixed a flaw in the parse_parts method. The second one was more complicated, as with the current interface of parse_parts (called by _parse_args), the bug can't be fixed. Let's take a simple example: WindowsPath(WindowsPath('./a:b')) and WindowsPath('a:b') - before the bugfix, they are equal. That happens because in both cases, parse_parts is called with ['a:b']. This part can be interpreted in two ways - either as the relative path 'b' with the drive 'a:', or as a file 'a' with the NTFS data-stream 'b'. That means that in some cases, passing the flattened _parts of a path to parse_parts is lossy. Therefore we have to a modify parse_parts's interface to enable passing more detailed information about the given parts. What I decided to do was allow passing tuples in addition to strings, thus supporting the old interface. The tuples would contain the drive, root and path parts, enough information to determine the correct parsing of path parts with data-streams, and maybe more future edge cases. After modifying parse_parts's interface, I changed _parse_args to use it and made Path.absolute, Path.expanduser and Path.__rtruediv__ pass Path objects to _parse_args instead of path parts, to preserve the path information. To solve the third bug I had to make small changes to both the resolve method and to Path.__str__. Notes In addition to the changes in the code, I've added regression tests and modified old incorrect tests. Details about drive-relative paths can be found here. https://bugs.python.org/issue36305

Open Graph Description: The bugs This PR fixes three bugs with path parsing in pathlib. The following examples show these bugs (when the cwd is C:\d): WindowsPath('C:a').absolute() should return WindowsPath('...

X Description: The bugs This PR fixes three bugs with path parsing in pathlib. The following examples show these bugs (when the cwd is C:\d): WindowsPath('C:a').absolute() should return WindowsPa...

Opengraph URL: https://github.com/python/cpython/pull/12361

X: @github

direct link

Domain: github.com

route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:8fb4ea6d-6c38-4e87-2d8a-6c7a17e3532c
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idE14E:1D772C:8757E6:B7CB71:696AB658
html-safe-noncefd0c32a19f5860b8f70e9c8da4a41457cda51ba4c185f6125beeb0b7ff8b4795
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMTRFOjFENzcyQzo4NzU3RTY6QjdDQjcxOjY5NkFCNjU4IiwidmlzaXRvcl9pZCI6IjIzMjA2ODQ4MDMwNDk1Njc4MzIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ==
visitor-hmac8fef6885560f31842f675933ca366ea531223cf1cec4feafdad4779dbf0d5947
hovercard-subject-tagpull_request:261718371
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/12361/files
twitter:imagehttps://avatars.githubusercontent.com/u/7690337?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/7690337?s=400&v=4
og:image:altThe bugs This PR fixes three bugs with path parsing in pathlib. The following examples show these bugs (when the cwd is C:\d): WindowsPath('C:a').absolute() should return WindowsPath('...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None4fa1799b6a53c2d30c950d74230781bef9e7f61138c72c7727e4b83f0743752b
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release41f276818bd204c4a30a0281fb3c576298d9474c
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/12361/files#start-of-content
https://github.com/
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F12361%2Ffiles
GitHub CopilotWrite better code with AIhttps://github.com/features/copilot
GitHub SparkBuild and deploy intelligent appshttps://github.com/features/spark
GitHub ModelsManage and compare promptshttps://github.com/features/models
MCP RegistryNewIntegrate external toolshttps://github.com/mcp
ActionsAutomate any workflowhttps://github.com/features/actions
CodespacesInstant dev environmentshttps://github.com/features/codespaces
IssuesPlan and track workhttps://github.com/features/issues
Code ReviewManage code changeshttps://github.com/features/code-review
GitHub Advanced SecurityFind and fix vulnerabilitieshttps://github.com/security/advanced-security
Code securitySecure your code as you buildhttps://github.com/security/advanced-security/code-security
Secret protectionStop leaks before they starthttps://github.com/security/advanced-security/secret-protection
Why GitHubhttps://github.com/why-github
Documentationhttps://docs.github.com
Bloghttps://github.blog
Changeloghttps://github.blog/changelog
Marketplacehttps://github.com/marketplace
View all featureshttps://github.com/features
Enterpriseshttps://github.com/enterprise
Small and medium teamshttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
App Modernizationhttps://github.com/solutions/use-case/app-modernization
DevSecOpshttps://github.com/solutions/use-case/devsecops
DevOpshttps://github.com/solutions/use-case/devops
CI/CDhttps://github.com/solutions/use-case/ci-cd
View all use caseshttps://github.com/solutions/use-case
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
View all industrieshttps://github.com/solutions/industry
View all solutionshttps://github.com/solutions
AIhttps://github.com/resources/articles?topic=ai
Software Developmenthttps://github.com/resources/articles?topic=software-development
DevOpshttps://github.com/resources/articles?topic=devops
Securityhttps://github.com/resources/articles?topic=security
View all topicshttps://github.com/resources/articles
Customer storieshttps://github.com/customer-stories
Events & webinarshttps://github.com/resources/events
Ebooks & reportshttps://github.com/resources/whitepapers
Business insightshttps://github.com/solutions/executive-insights
GitHub Skillshttps://skills.github.com
Documentationhttps://docs.github.com
Customer supporthttps://support.github.com
Community forumhttps://github.com/orgs/community/discussions
Trust centerhttps://github.com/trust-center
Partnershttps://github.com/partners
GitHub SponsorsFund open source developershttps://github.com/sponsors
Security Labhttps://securitylab.github.com
Maintainer Communityhttps://maintainers.github.com
Acceleratorhttps://github.com/accelerator
Archive Programhttps://archiveprogram.github.com
Topicshttps://github.com/topics
Trendinghttps://github.com/trending
Collectionshttps://github.com/collections
Enterprise platformAI-powered developer platformhttps://github.com/enterprise
GitHub Advanced SecurityEnterprise-grade security featureshttps://github.com/security/advanced-security
Copilot for BusinessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/premium-support
Pricinghttps://github.com/pricing
Search syntax tipshttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
documentationhttps://docs.github.com/search-github/github-code-search/understanding-github-code-search-syntax
Sign in https://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F12361%2Ffiles
Sign up https://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/12361/files
Reloadhttps://github.com/python/cpython/pull/12361/files
Reloadhttps://github.com/python/cpython/pull/12361/files
python https://github.com/python
cpythonhttps://github.com/python/cpython
Please reload this pagehttps://github.com/python/cpython/pull/12361/files
Notifications https://github.com/login?return_to=%2Fpython%2Fcpython
Fork 33.9k https://github.com/login?return_to=%2Fpython%2Fcpython
Star 71.1k https://github.com/login?return_to=%2Fpython%2Fcpython
Code https://github.com/python/cpython
Issues 5k+ https://github.com/python/cpython/issues
Pull requests 2.1k https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects 31 https://github.com/python/cpython/projects
Security Uh oh! There was an error while loading. Please reload this page. https://github.com/python/cpython/security
Please reload this pagehttps://github.com/python/cpython/pull/12361/files
Insights https://github.com/python/cpython/pulse
Code https://github.com/python/cpython
Issues https://github.com/python/cpython/issues
Pull requests https://github.com/python/cpython/pulls
Actions https://github.com/python/cpython/actions
Projects https://github.com/python/cpython/projects
Security https://github.com/python/cpython/security
Insights https://github.com/python/cpython/pulse
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
kmaorkhttps://github.com/kmaork
python:mainhttps://github.com/python/cpython/tree/main
kmaork:fix-issue-36305https://github.com/kmaork/cpython/tree/fix-issue-36305
Conversation 15 https://github.com/python/cpython/pull/12361
Commits 3 https://github.com/python/cpython/pull/12361/commits
Checks 0 https://github.com/python/cpython/pull/12361/checks
Files changed https://github.com/python/cpython/pull/12361/files
Please reload this pagehttps://github.com/python/cpython/pull/12361/files
bpo-36305: Fixes to path handling and parsing in pathlib https://github.com/python/cpython/pull/12361/files#top
Show all changes 3 commits https://github.com/python/cpython/pull/12361/files
15aadf9 Fixed bugs with drive-relative paths and NTFS ADS paths in pathlib kmaork Mar 15, 2019 https://github.com/python/cpython/pull/12361/commits/15aadf9b0e4551c157c04ae60592c84e4caae01d
c827f98 Merge branch 'master' into fix-issue-36305 kmaork Jan 16, 2020 https://github.com/python/cpython/pull/12361/commits/c827f982c328731129dcb033d1e21e800d6f8488
64fc342 Merge branch 'master' into fix-issue-36305 kmaork Feb 29, 2020 https://github.com/python/cpython/pull/12361/commits/64fc34274ff891042963ebce19106620a86ba410
Clear filters https://github.com/python/cpython/pull/12361/files
Please reload this pagehttps://github.com/python/cpython/pull/12361/files
Please reload this pagehttps://github.com/python/cpython/pull/12361/files
pathlib.py https://github.com/python/cpython/pull/12361/files#diff-fa525485738fc33d05b06c159172ff1f319c26e88d8c6bb39f7dbaae4dc4105c
test_pathlib.py https://github.com/python/cpython/pull/12361/files#diff-3dd97d2dc8816848d0b0c442e8fdeec9650b3de77935289a93f37ac6396ee17f
2019-03-15-22-50-27.bpo-36305.Pbkv6u.rst https://github.com/python/cpython/pull/12361/files#diff-5ef616d1e654d8d8472cd1b57af75ee9e20cf124cda7566a6659817eac7562bc
Lib/pathlib.pyhttps://github.com/python/cpython/pull/12361/files#diff-fa525485738fc33d05b06c159172ff1f319c26e88d8c6bb39f7dbaae4dc4105c
View file https://github.com/kmaork/cpython/blob/64fc34274ff891042963ebce19106620a86ba410/Lib/pathlib.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/12361/{{ revealButtonHref }}
https://github.com/python/cpython/pull/12361/files#diff-fa525485738fc33d05b06c159172ff1f319c26e88d8c6bb39f7dbaae4dc4105c
https://github.com/python/cpython/pull/12361/files#diff-fa525485738fc33d05b06c159172ff1f319c26e88d8c6bb39f7dbaae4dc4105c
https://github.com/python/cpython/pull/12361/files#diff-fa525485738fc33d05b06c159172ff1f319c26e88d8c6bb39f7dbaae4dc4105c
https://github.com/python/cpython/pull/12361/files#diff-fa525485738fc33d05b06c159172ff1f319c26e88d8c6bb39f7dbaae4dc4105c
https://github.com/python/cpython/pull/12361/files#diff-fa525485738fc33d05b06c159172ff1f319c26e88d8c6bb39f7dbaae4dc4105c
https://github.com/python/cpython/pull/12361/files#diff-fa525485738fc33d05b06c159172ff1f319c26e88d8c6bb39f7dbaae4dc4105c
https://github.com/python/cpython/pull/12361/files#diff-fa525485738fc33d05b06c159172ff1f319c26e88d8c6bb39f7dbaae4dc4105c
https://github.com/python/cpython/pull/12361/files#diff-fa525485738fc33d05b06c159172ff1f319c26e88d8c6bb39f7dbaae4dc4105c
https://github.com/python/cpython/pull/12361/files#diff-fa525485738fc33d05b06c159172ff1f319c26e88d8c6bb39f7dbaae4dc4105c
https://github.com/python/cpython/pull/12361/files#diff-fa525485738fc33d05b06c159172ff1f319c26e88d8c6bb39f7dbaae4dc4105c
https://github.com/python/cpython/pull/12361/files#diff-fa525485738fc33d05b06c159172ff1f319c26e88d8c6bb39f7dbaae4dc4105c
https://github.com/python/cpython/pull/12361/files#diff-fa525485738fc33d05b06c159172ff1f319c26e88d8c6bb39f7dbaae4dc4105c
https://github.com/python/cpython/pull/12361/files#diff-fa525485738fc33d05b06c159172ff1f319c26e88d8c6bb39f7dbaae4dc4105c
https://github.com/python/cpython/pull/12361/files#diff-fa525485738fc33d05b06c159172ff1f319c26e88d8c6bb39f7dbaae4dc4105c
https://github.com/python/cpython/pull/12361/files#diff-fa525485738fc33d05b06c159172ff1f319c26e88d8c6bb39f7dbaae4dc4105c
Lib/test/test_pathlib.pyhttps://github.com/python/cpython/pull/12361/files#diff-3dd97d2dc8816848d0b0c442e8fdeec9650b3de77935289a93f37ac6396ee17f
View file https://github.com/kmaork/cpython/blob/64fc34274ff891042963ebce19106620a86ba410/Lib/test/test_pathlib.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/12361/{{ revealButtonHref }}
https://github.com/python/cpython/pull/12361/files#diff-3dd97d2dc8816848d0b0c442e8fdeec9650b3de77935289a93f37ac6396ee17f
https://github.com/python/cpython/pull/12361/files#diff-3dd97d2dc8816848d0b0c442e8fdeec9650b3de77935289a93f37ac6396ee17f
barneygalehttps://github.com/barneygale
Feb 17, 2023https://github.com/python/cpython/pull/12361/files#r1110451710
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/12361/files
https://github.com/python/cpython/pull/12361/files#diff-3dd97d2dc8816848d0b0c442e8fdeec9650b3de77935289a93f37ac6396ee17f
https://github.com/python/cpython/pull/12361/files#diff-3dd97d2dc8816848d0b0c442e8fdeec9650b3de77935289a93f37ac6396ee17f
https://github.com/python/cpython/pull/12361/files#diff-3dd97d2dc8816848d0b0c442e8fdeec9650b3de77935289a93f37ac6396ee17f
https://github.com/python/cpython/pull/12361/files#diff-3dd97d2dc8816848d0b0c442e8fdeec9650b3de77935289a93f37ac6396ee17f
barneygalehttps://github.com/barneygale
Feb 17, 2023https://github.com/python/cpython/pull/12361/files#r1110452164
Learn morehttps://docs.github.com/articles/managing-disruptive-comments/#hiding-a-comment
Please reload this pagehttps://github.com/python/cpython/pull/12361/files
https://github.com/python/cpython/pull/12361/files#diff-3dd97d2dc8816848d0b0c442e8fdeec9650b3de77935289a93f37ac6396ee17f
https://github.com/python/cpython/pull/12361/files#diff-3dd97d2dc8816848d0b0c442e8fdeec9650b3de77935289a93f37ac6396ee17f
https://github.com/python/cpython/pull/12361/files#diff-3dd97d2dc8816848d0b0c442e8fdeec9650b3de77935289a93f37ac6396ee17f
https://github.com/python/cpython/pull/12361/files#diff-3dd97d2dc8816848d0b0c442e8fdeec9650b3de77935289a93f37ac6396ee17f
https://github.com/python/cpython/pull/12361/files#diff-3dd97d2dc8816848d0b0c442e8fdeec9650b3de77935289a93f37ac6396ee17f
https://github.com/python/cpython/pull/12361/files#diff-3dd97d2dc8816848d0b0c442e8fdeec9650b3de77935289a93f37ac6396ee17f
https://github.com/python/cpython/pull/12361/files#diff-3dd97d2dc8816848d0b0c442e8fdeec9650b3de77935289a93f37ac6396ee17f
https://github.com/python/cpython/pull/12361/files#diff-3dd97d2dc8816848d0b0c442e8fdeec9650b3de77935289a93f37ac6396ee17f
https://github.com/python/cpython/pull/12361/files#diff-3dd97d2dc8816848d0b0c442e8fdeec9650b3de77935289a93f37ac6396ee17f
https://github.com/python/cpython/pull/12361/files#diff-3dd97d2dc8816848d0b0c442e8fdeec9650b3de77935289a93f37ac6396ee17f
https://github.com/python/cpython/pull/12361/files#diff-3dd97d2dc8816848d0b0c442e8fdeec9650b3de77935289a93f37ac6396ee17f
Misc/NEWS.d/next/Library/2019-03-15-22-50-27.bpo-36305.Pbkv6u.rsthttps://github.com/python/cpython/pull/12361/files#diff-5ef616d1e654d8d8472cd1b57af75ee9e20cf124cda7566a6659817eac7562bc
View file https://github.com/kmaork/cpython/blob/64fc34274ff891042963ebce19106620a86ba410/Misc/NEWS.d/next/Library/2019-03-15-22-50-27.bpo-36305.Pbkv6u.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/12361/{{ revealButtonHref }}
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.