This repository was archived by the owner on Jun 8, 2021. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Expand file tree Collapse file tree 1 file changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -142,7 +142,7 @@ pub fn filename_from_uri(uri: &str) -> Result<(std::path::PathBuf, Option<GStrin
142
142
let mut hostname = ptr:: null_mut ( ) ;
143
143
let mut error = ptr:: null_mut ( ) ;
144
144
let ret = g_filename_from_uri ( uri. to_glib_none ( ) . 0 , & mut hostname, & mut error) ;
145
- if error. is_null ( ) { Ok ( ( from_glib_full ( ret) , Some ( from_glib_full ( hostname) ) ) ) } else { Err ( from_glib_full ( error) ) }
145
+ if error. is_null ( ) { Ok ( ( from_glib_full ( ret) , from_glib_full ( hostname) ) ) } else { Err ( from_glib_full ( error) ) }
146
146
}
147
147
}
148
148
@@ -229,4 +229,26 @@ mod tests {
229
229
check_setenv ( "Test" ) ;
230
230
check_setenv ( "Тест" ) ; // "Test" in Russian
231
231
}
232
+
233
+ #[ test]
234
+ fn test_filename_from_uri ( ) {
235
+ use gstring:: GString ;
236
+ use std:: path:: PathBuf ;
237
+ let uri: GString = "file:///foo/bar.txt" . into ( ) ;
238
+ if let Ok ( ( filename, hostname) ) = :: filename_from_uri ( & uri) {
239
+ assert_eq ! ( filename, PathBuf :: from( r"/foo/bar.txt" ) ) ;
240
+ assert_eq ! ( hostname, None ) ;
241
+ } else {
242
+ unreachable ! ( ) ;
243
+ }
244
+
245
+ let uri: GString = "file://host/foo/bar.txt" . into ( ) ;
246
+ if let Ok ( ( filename, hostname) ) = :: filename_from_uri ( & uri) {
247
+ assert_eq ! ( filename, PathBuf :: from( r"/foo/bar.txt" ) ) ;
248
+ assert_eq ! ( hostname, Some ( GString :: from( "host" ) ) ) ;
249
+ } else {
250
+ unreachable ! ( ) ;
251
+ }
252
+
253
+ }
232
254
}
You can’t perform that action at this time.
0 commit comments