lmi
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [lmi] Path validation in boost and std::fs (was: Replacing boost wit


From: Vadim Zeitlin
Subject: Re: [lmi] Path validation in boost and std::fs (was: Replacing boost with C++ standard library)
Date: Fri, 16 Mar 2018 19:49:37 +0100

 Hello,

 I'd like to return to this topic to discuss how to handle an important
difference between Boost.Filesystem and std::filesystem libraries. The
former one has the concept of "checkers", which are used whenever paths are
constructed to verify their validity, while the latter one seems to take a
much more relaxed, Unix-like, approach and doesn't impose any restrictions
at all on the path components.

 This affects a lot of operations, even when it might not be expected: for
example, the unit test checking that fs::change_extension("..", "..")
throws, which passes with Boost 1.33 because the "..." sequence fails a
validity check, starts failing after rewriting it as mostly equivalent
fs::path("..").replace_extension("..") as this just produces "...." path
without any exceptions being thrown. Other unit tests fail because
validate_path() now doesn't check for any invalid characters in the path,
while the tests expect it to do it for characters such as '<', '|' and '>'.

 It is impossible to modify std::filesystem to perform validity checks, so
what should we do about this? One possibility would be to always use our
own function (lmi_path()?) for creating fs::path objects that would perform
all the checks previously done by Boost.Filesystem itself. The advantage of
this approach is that it should preserve the behaviour of the existing
code, but the disadvantage is that it will make the code less clear when
reading it and less convenient when writing it and some invalid paths could
still slip through because fs::path ctor from string is not explicit and so
could still be used inadvertently.

 Moreover, I'm not really sure how much value do these checks represent.
Any attempt to actually use a path with invalid characters in it would fail
anyhow under systems imposing such restrictions (i.e. MSW), so what do we
gain from checking for them preventively? So my person preference would be
to actually just stop doing these checks and not worry about it. But I'm
not sure if you would agree with me here...

 There is also a compromise solution of only performing these checks in
validate_path() itself. This would then allow to do such checks when we
really need them, while still allowing us to use just fs::path directly
elsewhere.

 Which one of these solutions would you prefer to put in place? Or do you
see some other, even better, one?

 Thanks in advance,
VZ


reply via email to

[Prev in Thread] Current Thread [Next in Thread]