TruePath icon indicating copy to clipboard operation
TruePath copied to clipboard

Forbid construction of incorrect absolute paths

Open ForNeVeR opened this issue 1 year ago • 5 comments

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.

ForNeVeR avatar Sep 22 '24 20:09 ForNeVeR

Hi. I apologize for the long silence and delay. If no one else has done it, can I take it to work?

Kataane avatar Nov 09 '24 08:11 Kataane

Of course, feel free to take this one.

ForNeVeR avatar Nov 09 '24 14:11 ForNeVeR

I'd like to ask a couple of clarifying questions about the task:

  1. 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?

  2. So there should be the same behavior for: AbsolutePath(“smth”) / new RelativePath(“...”) and vice versa? An exception should be thrown?

Kataane avatar Nov 10 '24 06:11 Kataane

  1. 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.

  1. 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.

ForNeVeR avatar Nov 10 '24 15:11 ForNeVeR

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.

ForNeVeR avatar Jun 18 '25 19:06 ForNeVeR