Use Python's standard filesystem encoding for command-line arguments#4507
Merged
Use Python's standard filesystem encoding for command-line arguments#4507
Conversation
The idea in this PR is to converge on Python's `fsdecode` and `fsencode` for argument manipulation. This seems to match up with the Python standard library's assumptions: namely, on Windows, we use `fsdecode` to get back to Unicode strings: https://github.com/python/cpython/blob/54bbb5e3363ef3634f1fd7521ba3f3c42c81a331/Lib/subprocess.py#L561 So let's start by dropping this utility and going straight for `fsdecode` here to match.
This can apparently never be `None`, as of Python 3.2.
On Windows, converting command-line arguments (hopefully!!!) only needs to deal with valid strings from the OS. So it is not really relevant to test with non-UTF-8, non-surrogate bytes.
Member
Author
|
Incredibly, this actually seems to have addressed the |
Member
Author
|
OK, this does seem to work—at least for our tests—and I haven't thought of a good reason it should be wrong over the last couple of days. So I'm going to merge this one, with considerable trepidation, and we'll see if anything breaks in the wild! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This is very much an experiment, but it's an attempt to address persistent issues with invoking command-line tools with non-ASCII arguments. For example, the
replaygainplugin wants to invokeffmpegon filenames that might contain special characters. Doing this in a cross-platform way has always been extremely fraught—it's hard to get it to work right simultaneously on Unix (where filenames are plain bytes that need not obey any specific encoding) and on Windows (where filenames are weird, but they are closer to being Unicode strings).The experiment here is to centralize on the Python standard library's implicit recommendations for this:
fsencodeandfsdecode. These use surrogate escaping (at least in most configurations??), so they probably shouldn't crash. Thesubprocessmodule also apparently assumes this is the right encoding for CLI argument stuff, at least on Windows:https://github.com/python/cpython/blob/54bbb5e3363ef3634f1fd7521ba3f3c42c81a331/Lib/subprocess.py#L561
…so hopefully using this encoding everywhere should make things better on Windows and no worse on Unix.
The hope is to address some CI failures that come from the
replaygaininvokingffmpegon Windows.