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

Commit

Permalink
Merge pull request #463 from philn/filename-from-uri-fix
Browse files Browse the repository at this point in the history
Filename from uri fix
  • Loading branch information
sdroege committed Feb 22, 2019
2 parents db6b85e + 23203d4 commit 03b4191
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/utils.rs
Expand Up @@ -142,7 +142,7 @@ pub fn filename_from_uri(uri: &str) -> Result<(std::path::PathBuf, Option<GStrin
let mut hostname = ptr::null_mut();
let mut error = ptr::null_mut();
let ret = g_filename_from_uri(uri.to_glib_none().0, &mut hostname, &mut error);
if error.is_null() { Ok((from_glib_full(ret), Some(from_glib_full(hostname)))) } else { Err(from_glib_full(error)) }
if error.is_null() { Ok((from_glib_full(ret), from_glib_full(hostname))) } else { Err(from_glib_full(error)) }
}
}

Expand Down Expand Up @@ -229,4 +229,26 @@ mod tests {
check_setenv("Test");
check_setenv("Тест"); // "Test" in Russian
}

#[test]
fn test_filename_from_uri() {
use gstring::GString;
use std::path::PathBuf;
let uri: GString = "file:///foo/bar.txt".into();
if let Ok((filename, hostname)) = ::filename_from_uri(&uri) {
assert_eq!(filename, PathBuf::from(r"/foo/bar.txt"));
assert_eq!(hostname, None);
} else {
unreachable!();
}

let uri: GString = "file://host/foo/bar.txt".into();
if let Ok((filename, hostname)) = ::filename_from_uri(&uri) {
assert_eq!(filename, PathBuf::from(r"/foo/bar.txt"));
assert_eq!(hostname, Some(GString::from("host")));
} else {
unreachable!();
}

}
}

0 comments on commit 03b4191

Please sign in to comment.