Call fs::u8path()
to convert some UTF-8 string literals to paths, instead of relying on the implicit conversion. Fake Macro pointed out in #24306 (review) that fs_tests
are incorrectly decoding some literal UTF-8 paths using the current windows codepage, instead of treating them as UTF-8. This could cause test failures depending what environment windows tests are run under.
The fs::path
class exists to avoid problems like this, but because it is lenient with const char*
conversions, under assumption that they are “safe as long as the literals are ASCII”, bugs like this are still possible.
If we think this is a concern, followup options to try to prevent this bug in the future are:
- Do nothing
- Improve the “safe as long as the literals are ASCII” comment. Make it clear that non-ASCII strings are invalid.
- Drop the implicit
const char*
conversion functions. This would be nice because it would simplifify thefs::path
class a little, while making it safer. Drawback is that it would require some more verbosity from callers. For example, instead ofGetDataDirNet() / "mempool.dat"
they would have to writeGetDataDirNet() / fs::u8path("mempool.dat")
- Keep the implicit
const char*
conversion functions, but make them callfs::u8path()
internally. Change the “safe as long as the literals are ASCII” comment to “safe as long as the literals are UTF-8”.
I’d be happy with 0, 1, or 2. I’d be a little resistant to 3 even though it was would add more safety, because it would slightly increase complexity, and because I think it would encourage representing paths as strings, when I think there are so many footguns associated with paths as strings, that it’s best to convert strings to paths at the earliest point possible, and convert paths to strings at the latest point possible.