GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||
GeezerVison is showing github.com — gh-122143: Fix os.path.splitroot() and os.path.normpath() for undecodable bytes paths on Windows by gianghungtien · Pull Request #154585 · python/cpython Conversation
Contributor
On Windows, >>> ntpath.splitroot(b"foo\x88")
Traceback (most recent call last):
...
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x88 in position 3: invalid start byte3.12 returned Both helpers declare The fixThis implements the approach eryksun suggested on the issue: let the native helpers fall back to the pure Python implementation for paths they cannot convert.
The alternative discussed on the issue — changing the Windows filesystem error handler to The other route to a decode failure, Behaviour changes
For a path that is decodable, nothing changes: the native helper still does all the work, and the fallback is reached only on the error path. Tests
Verified on Windows with
Sorry, something went wrong. Uh oh!
There was an error while loading. Please reload this page. All reactions…ndecodable bytes paths on Windows The native helpers nt._path_splitroot_ex() and nt._path_normpath() convert the path to a wide string first, so a bytes path which cannot be decoded with the filesystem encoding (UTF-8 with the "surrogatepass" error handler on Windows) failed with UnicodeDecodeError. os.path.splitroot() and os.path.splitdrive() regressed this way in 3.13, when the native helper was added; os.path.normpath() has behaved this way since the native helper was added in 3.12. Enable suppress_value_error for both helpers and delegate such paths to the pure Python implementations, which operate on bytes directly, as they already do on POSIX. path_converter() now keeps the original object when it suppresses a ValueError, so that the fallback can be given the path. This also fixes os.path.split(), os.path.abspath() and os.path.realpath(), which are built on top of the two helpers.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ReviewersNo reviewsUh oh!
There was an error while loading. Please reload this page. AssigneesNo one assignedLabelsProjectsMilestoneNo milestoneDevelopmentSuccessfully merging this pull request may close these issues. Uh oh!
There was an error while loading. Please reload this page. Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later. | ||||||||||||||||||
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |