Forbid construction of incorrect absolute paths
Absolute paths such as /.. (Unix) or X:\.. (Windows) should be forbidden. Let's add the corresponding validation into the AbsolutePath constructor.
Also check the behavior of new AbsolutePath("smth") / new RelativePath("..") — it should be the same w.r.t. the exceptions thrown.
Hi. I apologize for the long silence and delay. If no one else has done it, can I take it to work?
Of course, feel free to take this one.
I'd like to ask a couple of clarifying questions about the task:
-
Regarding the prohibition of absolute paths: Should an exception be thrown if such paths (like /.. for Unix or X:.. for Windows) are detected in the AbsolutePath constructor?
-
So there should be the same behavior for:
AbsolutePath(“smth”) / new RelativePath(“...”)and vice versa? An exception should be thrown?
- Regarding the prohibition of absolute paths: Should an exception be thrown if such paths (like /.. for Unix or X:.. for Windows) are detected in the AbsolutePath constructor?
Yes. If a path is impossible to represent as an absolute one, then let's throw an exception.
- So there should be the same behavior for:
AbsolutePath(“smth”) / new RelativePath(“...”)and vice versa? An exception should be thrown?
Same behavior as with new AbsolutePath("smth"), yes. And I think you mean new LocalPath and not new RelativePath? For now I think let's not touch that one. I am not yet sure if we want the same restrictions about incorrect absolute paths to apply to the LocalPath. Probably not.
Hmm, look what I found in POSIX:
The special filename dot shall refer to the directory specified by its predecessor. The special filename dot-dot shall refer to the parent directory of its predecessor directory. As a special case, in the root directory, dot-dot may refer to the root directory itself.
— https://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap04.html#tag_04_11
On the other hand, Windows doesn't have the same notation; .NET's Path::GetDirectoryName returns null for a rooted path.