@@ -148,9 +148,6 @@ url = { version = "2", features = ["debugger_visualizer"] }
148148 feature = "debugger_visualizer" ,
149149 debugger_visualizer( natvis_file = "../../debug_metadata/url.natvis" )
150150) ]
151- // We use std::os::wasi::prelude::OsStrExt, and that is conditionally feature gated
152- // to be unstable on wasm32-wasip2. https://github.com/rust-lang/rust/issues/130323
153- #![ cfg_attr( all( target_os = "wasi" , target_env = "p2" ) , feature( wasip2) ) ]
154151
155152pub use form_urlencoded;
156153
@@ -2985,8 +2982,6 @@ fn path_to_file_url_segments(
29852982 use std:: os:: hermit:: ffi:: OsStrExt ;
29862983 #[ cfg( any( unix, target_os = "redox" ) ) ]
29872984 use std:: os:: unix:: prelude:: OsStrExt ;
2988- #[ cfg( target_os = "wasi" ) ]
2989- use std:: os:: wasi:: prelude:: OsStrExt ;
29902985 if !path. is_absolute ( ) {
29912986 return Err ( ( ) ) ;
29922987 }
@@ -2996,10 +2991,16 @@ fn path_to_file_url_segments(
29962991 for component in path. components ( ) . skip ( 1 ) {
29972992 empty = false ;
29982993 serialization. push ( '/' ) ;
2994+ #[ cfg( not( target_os = "wasi" ) ) ]
29992995 serialization. extend ( percent_encode (
30002996 component. as_os_str ( ) . as_bytes ( ) ,
30012997 SPECIAL_PATH_SEGMENT ,
30022998 ) ) ;
2999+ #[ cfg( target_os = "wasi" ) ]
3000+ serialization. extend ( percent_encode (
3001+ component. as_os_str ( ) . to_string_lossy ( ) . as_bytes ( ) ,
3002+ SPECIAL_PATH_SEGMENT ,
3003+ ) ) ;
30033004 }
30043005 if empty {
30053006 // An URL’s path must not be empty.
@@ -3093,13 +3094,12 @@ fn file_url_segments_to_pathbuf(
30933094) -> Result < PathBuf , ( ) > {
30943095 use alloc:: vec:: Vec ;
30953096 use percent_encoding:: percent_decode;
3097+ #[ cfg( not( target_os = "wasi" ) ) ]
30963098 use std:: ffi:: OsStr ;
30973099 #[ cfg( target_os = "hermit" ) ]
30983100 use std:: os:: hermit:: ffi:: OsStrExt ;
30993101 #[ cfg( any( unix, target_os = "redox" ) ) ]
31003102 use std:: os:: unix:: prelude:: OsStrExt ;
3101- #[ cfg( target_os = "wasi" ) ]
3102- use std:: os:: wasi:: prelude:: OsStrExt ;
31033103 use std:: path:: PathBuf ;
31043104
31053105 if host. is_some ( ) {
@@ -3125,8 +3125,12 @@ fn file_url_segments_to_pathbuf(
31253125 bytes. push ( b'/' ) ;
31263126 }
31273127
3128- let os_str = OsStr :: from_bytes ( & bytes) ;
3129- let path = PathBuf :: from ( os_str) ;
3128+ #[ cfg( not( target_os = "wasi" ) ) ]
3129+ let path = PathBuf :: from ( OsStr :: from_bytes ( & bytes) ) ;
3130+ #[ cfg( target_os = "wasi" ) ]
3131+ let path = String :: from_utf8 ( bytes)
3132+ . map ( |path| PathBuf :: from ( path) )
3133+ . map_err ( |_| ( ) ) ?;
31303134
31313135 debug_assert ! (
31323136 path. is_absolute( ) ,
0 commit comments