@@ -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
@@ -2892,8 +2889,6 @@ fn path_to_file_url_segments(
2892
2889
use percent_encoding:: percent_encode;
2893
2890
#[ cfg( any( unix, target_os = "redox" ) ) ]
2894
2891
use std:: os:: unix:: prelude:: OsStrExt ;
2895
- #[ cfg( target_os = "wasi" ) ]
2896
- use std:: os:: wasi:: prelude:: OsStrExt ;
2897
2892
if !path. is_absolute ( ) {
2898
2893
return Err ( ( ) ) ;
2899
2894
}
@@ -2903,10 +2898,16 @@ fn path_to_file_url_segments(
2903
2898
for component in path. components ( ) . skip ( 1 ) {
2904
2899
empty = false ;
2905
2900
serialization. push ( '/' ) ;
2901
+ #[ cfg( not( target_os = "wasi" ) ) ]
2906
2902
serialization. extend ( percent_encode (
2907
2903
component. as_os_str ( ) . as_bytes ( ) ,
2908
2904
SPECIAL_PATH_SEGMENT ,
2909
2905
) ) ;
2906
+ #[ cfg( target_os = "wasi" ) ]
2907
+ serialization. extend ( percent_encode (
2908
+ component. as_os_str ( ) . to_string_lossy ( ) . as_bytes ( ) ,
2909
+ SPECIAL_PATH_SEGMENT ,
2910
+ ) ) ;
2910
2911
}
2911
2912
if empty {
2912
2913
// An URL’s path must not be empty.
@@ -2997,11 +2998,10 @@ fn file_url_segments_to_pathbuf(
2997
2998
) -> Result < PathBuf , ( ) > {
2998
2999
use alloc:: vec:: Vec ;
2999
3000
use percent_encoding:: percent_decode;
3001
+ #[ cfg( not( target_os = "wasi" ) ) ]
3000
3002
use std:: ffi:: OsStr ;
3001
3003
#[ cfg( any( unix, target_os = "redox" ) ) ]
3002
3004
use std:: os:: unix:: prelude:: OsStrExt ;
3003
- #[ cfg( target_os = "wasi" ) ]
3004
- use std:: os:: wasi:: prelude:: OsStrExt ;
3005
3005
use std:: path:: PathBuf ;
3006
3006
3007
3007
if host. is_some ( ) {
@@ -3027,8 +3027,12 @@ fn file_url_segments_to_pathbuf(
3027
3027
bytes. push ( b'/' ) ;
3028
3028
}
3029
3029
3030
- let os_str = OsStr :: from_bytes ( & bytes) ;
3031
- let path = PathBuf :: from ( os_str) ;
3030
+ #[ cfg( not( target_os = "wasi" ) ) ]
3031
+ let path = PathBuf :: from ( OsStr :: from_bytes ( & bytes) ) ;
3032
+ #[ cfg( target_os = "wasi" ) ]
3033
+ let path = String :: from_utf8 ( bytes)
3034
+ . map ( |path| PathBuf :: from ( path) )
3035
+ . map_err ( |_| ( ) ) ?;
3032
3036
3033
3037
debug_assert ! (
3034
3038
path. is_absolute( ) ,
0 commit comments