File tree Expand file tree Collapse file tree
crates/anstyle-hyperlink/src Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -63,16 +63,29 @@ const PATH_SEGMENT: &percent_encoding::AsciiSet = &PATH.add(b'/').add(b'%');
6363const SPECIAL_PATH_SEGMENT : & percent_encoding:: AsciiSet = & PATH_SEGMENT . add ( b'\\' ) ;
6464
6565fn encode_path ( path : & std:: path:: Path , url : & mut String ) {
66- // skip the root component
6766 let mut is_path_empty = true ;
68- for component in path. components ( ) . skip ( 1 ) {
67+
68+ for component in path. components ( ) {
6969 is_path_empty = false ;
70- url. push_str ( URL_PATH_SEP ) ;
71- let component = component. as_os_str ( ) . to_str ( ) ?;
72- url. extend ( percent_encoding:: percent_encode (
73- component. as_bytes ( ) ,
74- SPECIAL_PATH_SEGMENT ,
75- ) ) ;
70+ match component {
71+ std:: path:: Component :: Prefix ( prefix) => {
72+ let component = prefix. as_os_str ( ) . to_string_lossy ( ) ;
73+ url. push_str ( & component) ;
74+ }
75+ std:: path:: Component :: RootDir => { }
76+ std:: path:: Component :: CurDir => { }
77+ std:: path:: Component :: ParentDir => {
78+ url. push_str ( ".." ) ;
79+ }
80+ std:: path:: Component :: Normal ( part) => {
81+ url. push_str ( URL_PATH_SEP ) ;
82+ let component = part. to_string_lossy ( ) ;
83+ url. extend ( percent_encoding:: percent_encode (
84+ component. as_bytes ( ) ,
85+ SPECIAL_PATH_SEGMENT ,
86+ ) ) ;
87+ }
88+ }
7689 }
7790 if is_path_empty {
7891 // An URL's path must not be empty
You can’t perform that action at this time.
0 commit comments