by oguz-ismail · 1y ago · 0 comments
$ touch $'a.\xFF'
$ find -name $'*.\xFF'
./a.?
$ ./fd -e $'\xFF'
error: invalid UTF-8 was detected in one or more arguments
Usage: fd [OPTIONS] [pattern] [path]...
For more information, try '--help'.
$
$ touch III
$ LC_ALL=tr_TR.UTF-8 find -iname 'iii'
$ LC_ALL=tr_TR.UTF-8 ./fd 'iii'
III
$
Every fucking timeFile extensions - or their names - mean absolutely nothing with ELF. Maybe $APPLICATION decides to use the filename to store non-ASCII/Unicode parity data... because it was developed in a closet with infinite funding. Who knows. Who's to say.
Contrived, yes, but practical. Imposing isn't. The filesystem may contain more than this can handle.
Regardless, the point is moot because `fd` handles the filenames gracefully you just need to use a different flag [0].
It's also what made Python 3 very impractical when it orginally came around. It wasn't fixed until several versions in despite being a common complaint among actual users.
[1] https://docs.rs/regex/latest/regex/#opt-out-of-unicode-suppo...
For >99.99% of usecases, file paths are textual data, and people do expect to view them as text. And it's high time that kernels should start enforcing that they act as text, because it constitutes a security vulnerability for a good deal of software while providing exceedingly low value.
While I support the UTF-8 everywhere movement with every fiber of my body, that still sounds like a hard sell for all vintage computer enthusiasts, embedded developers, and anyone else, really.
(I'm the author of ripgrep, and this is my way of gently suggesting that "filenames aren't even text" isn't an especially useful model.)
As for "filenames aren't even text" not being a useful model, to me text is a `&str` or `String` or `OsString`, filenames are a `Path` or `PathBuf`. We have different types for paths & strings because they represent different things, and have different valid contents. All I mean by that is the types are different, and the types you use for text shouldn't be the same as the types you use for paths.
$ fd '(?-u:\xFF)'
a.�But if you do, fd still supports it. You just can't use the `-e/--extension` convenience:
$ touch $'a.\xFF'
$ fd '.*\.(?-u:\xFF)'
a.�
That is, `fd` requires that the regex patterns you give it be valid UTF-8, but that doesn't mean the patterns themselves are limited to only matching valid UTF-8. You can disable Unicode mode and match raw bytes via escape sequences (that's what `(?-u:\xFF)` is doing).So as a matter of fact, the sibling comments get the analysis wrong here. `fd` doesn't assume all of its file paths are valid UTF-8. As demonstrated above, it handles non-UTF-8 paths just fine. But some conveniences, like specifying a file extension, do require valid UTF-8.
Here an invalid UTF-8 is passed via command line arguments. If it is desired to support this, the correct way is to use args_os https://doc.rust-lang.org/beta/std/env/fn.args_os.html which gives an iterator that yields OsString.
Nobody cares that valid filenames are anything except the null byte and /. Tell me one valid usecase for a non-UTF8 filename.
You wish to find and delete them all, now that they've turned your home directory into a monstrosity.
fd does that for English only. See the III/iii case in my comment; iii capitalizes to İİİ in Turkish, there's no way to have fd respect that.