File tree Expand file tree Collapse file tree 1 file changed +2
-44
lines changed Expand file tree Collapse file tree 1 file changed +2
-44
lines changed Original file line number Diff line number Diff line change 11mod clean;
22
3- use std:: path:: Component ;
4-
53use camino:: Utf8Path ;
64use camino:: Utf8PathBuf ;
75
8- pub trait Utf8PathClean {
9- fn clean ( & self ) -> Utf8PathBuf ;
10- }
11-
12- impl Utf8PathClean for Utf8Path {
13- fn clean ( & self ) -> Utf8PathBuf {
14- clean_utf8_path ( self )
15- }
16- }
17-
18- impl Utf8PathClean for Utf8PathBuf {
19- fn clean ( & self ) -> Utf8PathBuf {
20- clean_utf8_path ( self )
21- }
22- }
23-
24- pub fn clean_utf8_path ( path : & Utf8Path ) -> Utf8PathBuf {
25- let mut out = Vec :: new ( ) ;
26-
27- for comp in path. as_std_path ( ) . components ( ) {
28- match comp {
29- Component :: CurDir => ( ) ,
30- Component :: ParentDir => match out. last ( ) {
31- Some ( Component :: RootDir ) => ( ) ,
32- Some ( Component :: Normal ( _) ) => {
33- out. pop ( ) ;
34- }
35- None | Some ( Component :: CurDir | Component :: ParentDir | Component :: Prefix ( _) ) => {
36- out. push ( comp) ;
37- }
38- } ,
39- comp => out. push ( comp) ,
40- }
41- }
42-
43- if out. is_empty ( ) {
44- Utf8PathBuf :: from ( "." )
45- } else {
46- let cleaned: std:: path:: PathBuf = out. iter ( ) . collect ( ) ;
47- Utf8PathBuf :: from_path_buf ( cleaned) . expect ( "Path should still be UTF-8" )
48- }
49- }
6+ use clean:: clean_utf8_path;
7+ pub use clean:: Utf8PathClean ;
508
519/// Django's `safe_join` equivalent - join paths and ensure result is within base
5210pub fn safe_join ( base : & Utf8Path , name : & str ) -> Result < Utf8PathBuf , SafeJoinError > {
You can’t perform that action at this time.
0 commit comments