@@ -148,9 +148,6 @@ url = { version = "2", features = ["debugger_visualizer"] }
148
148
feature = "debugger_visualizer" ,
149
149
debugger_visualizer( natvis_file = "../../debug_metadata/url.natvis" )
150
150
) ]
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) ) ]
154
151
155
152
pub use form_urlencoded;
156
153
@@ -2985,8 +2982,6 @@ fn path_to_file_url_segments(
2985
2982
use std:: os:: hermit:: ffi:: OsStrExt ;
2986
2983
#[ cfg( any( unix, target_os = "redox" ) ) ]
2987
2984
use std:: os:: unix:: prelude:: OsStrExt ;
2988
- #[ cfg( target_os = "wasi" ) ]
2989
- use std:: os:: wasi:: prelude:: OsStrExt ;
2990
2985
if !path. is_absolute ( ) {
2991
2986
return Err ( ( ) ) ;
2992
2987
}
@@ -2996,10 +2991,16 @@ fn path_to_file_url_segments(
2996
2991
for component in path. components ( ) . skip ( 1 ) {
2997
2992
empty = false ;
2998
2993
serialization. push ( '/' ) ;
2994
+ #[ cfg( not( target_os = "wasi" ) ) ]
2999
2995
serialization. extend ( percent_encode (
3000
2996
component. as_os_str ( ) . as_bytes ( ) ,
3001
2997
SPECIAL_PATH_SEGMENT ,
3002
2998
) ) ;
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
+ ) ) ;
3003
3004
}
3004
3005
if empty {
3005
3006
// An URL’s path must not be empty.
@@ -3093,13 +3094,12 @@ fn file_url_segments_to_pathbuf(
3093
3094
) -> Result < PathBuf , ( ) > {
3094
3095
use alloc:: vec:: Vec ;
3095
3096
use percent_encoding:: percent_decode;
3097
+ #[ cfg( not( target_os = "wasi" ) ) ]
3096
3098
use std:: ffi:: OsStr ;
3097
3099
#[ cfg( target_os = "hermit" ) ]
3098
3100
use std:: os:: hermit:: ffi:: OsStrExt ;
3099
3101
#[ cfg( any( unix, target_os = "redox" ) ) ]
3100
3102
use std:: os:: unix:: prelude:: OsStrExt ;
3101
- #[ cfg( target_os = "wasi" ) ]
3102
- use std:: os:: wasi:: prelude:: OsStrExt ;
3103
3103
use std:: path:: PathBuf ;
3104
3104
3105
3105
if host. is_some ( ) {
@@ -3125,8 +3125,12 @@ fn file_url_segments_to_pathbuf(
3125
3125
bytes. push ( b'/' ) ;
3126
3126
}
3127
3127
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 ( |_| ( ) ) ?;
3130
3134
3131
3135
debug_assert ! (
3132
3136
path. is_absolute( ) ,
0 commit comments