3 ms·
> Moreover, the "fixed" version is less correct than the version I used 11 years ago, because previously it correctly handled filename command-line arguments e
by LegionMammal978 2y ago
> Moreover, the "fixed" version is less correct than the version I used 11 years ago, because previously it correctly handled filename command-line arguments even if they weren't UTF-8. Now it won't, and there's evidently no way to fix it.
Isn't fixing this the whole point of Python's "surrogateescape" handling? Certainly, if I put the filename straight from sys.argv into open(), Python will pass it through just fine:
$ printf 'Hello, world!' > $'\xFF.txt'
$ python3 -c 'import sys; print(open(sys.argv[1]).read())' $'\xFF.txt'
Hello, world!
Though I suppose it could still be problematic for logging filenames or otherwise displaying them.
- kragen 2y agoI didn't realize that surrogateescape (UTF-8B) had become the default! If so, that's a great improvement. Thank you for the correction. (I can confirm that Python does indeed try to open "\377.txt" on my machine with this command line.)