Skip to content
This repository was archived by the owner on Jun 8, 2021. It is now read-only.

Commit 03b4191

Browse files
authored
Merge pull request #463 from philn/filename-from-uri-fix
Filename from uri fix
2 parents db6b85e + 23203d4 commit 03b4191

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/utils.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ pub fn filename_from_uri(uri: &str) -> Result<(std::path::PathBuf, Option<GStrin
142142
let mut hostname = ptr::null_mut();
143143
let mut error = ptr::null_mut();
144144
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)) }
146146
}
147147
}
148148

@@ -229,4 +229,26 @@ mod tests {
229229
check_setenv("Test");
230230
check_setenv("Тест"); // "Test" in Russian
231231
}
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+
}
232254
}

0 commit comments

Comments
 (0)