ForNeVeR / TruePath

File path abstraction library for .NET.
https://fornever.github.io/TruePath/
MIT License
55 stars 9 forks source link

Forbid construction of incorrect absolute paths #95

Open ForNeVeR opened 2 months ago

ForNeVeR commented 2 months ago

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.

Kataane commented 2 weeks ago

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

ForNeVeR commented 2 weeks ago

Of course, feel free to take this one.

Kataane commented 2 weeks ago

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?

ForNeVeR commented 2 weeks ago
  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.