chipsenkbeil / typed-path

Provides typed variants of Path and PathBuf for Unix and Windows
38 stars 6 forks source link

add Path Traversal Protection #20

Closed TheAlgorythm closed 7 months ago

TheAlgorythm commented 9 months ago

closes #19

TheAlgorythm commented 9 months ago

This are just a few basic additions in order to get familiar with the code base. Is there a way to generalise over Path and Utf8Path/Path and Utf8Path? This would be really helpful as the encoding is at a lower level and don't have to double the types.

chipsenkbeil commented 9 months ago

This are just a few basic additions in order to get familiar with the code base. Is there a way to generalise over Path and Utf8Path/Path and Utf8Path? This would be really helpful as the encoding is at a lower level and don't have to double the types.

Unfortunately, you need two distinct types if you want to handle both. While a lot of code can be shared, they operate on byte slices and str slices. Structs that work with str slices can be easily converted into the byte slice form, but the other way around is unsafe. Part of the type safety construct.

If you want to minimize duplicate code, my recommendation is to either have a trait that works on byte slices that you can apply to both, or implement the logic in a macro that generates both struct impls.

chipsenkbeil commented 7 months ago

23 is implementing this functionality, so going to close this out.