Skip to content

Commit

Permalink
Fix for fs path encoding. Fixes #25
Browse files Browse the repository at this point in the history
  • Loading branch information
yury committed Nov 7, 2024
1 parent fc98d67 commit bb09087
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions cidre/src/cf/url.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{os::unix::prelude::OsStrExt, path::Path};
use std::path::Path;

use crate::{arc, cf, define_cf_type};

Expand Down Expand Up @@ -61,8 +61,8 @@ impl Url {

#[inline]
pub fn with_path(path: &Path, is_dir: bool) -> Option<arc::R<Url>> {
let bytes = path.as_os_str().as_bytes();
let encoding = cf::StringEncoding::sys_encoding();
let bytes = path.to_str()?.as_bytes();
let encoding = cf::StringEncoding::UTF8;
let Some(path) = cf::String::create_with_bytes_no_copy_in(
bytes,
encoding,
Expand Down Expand Up @@ -250,3 +250,18 @@ extern "C-unwind" {
) -> Option<arc::R<cf::String>>;
fn CFURLHasDirectoryPath(anURL: &Url) -> bool;
}

#[cfg(test)]
mod tests {
use std::path::Path;

use crate::cf;

#[test]
fn basics() {
let path = Path::new("/tmp/MacBook Airのマイク");
let url = cf::Url::with_file_path(path).unwrap();
let str = url.fs_path_posix().unwrap();
assert_eq!("/tmp/MacBook Airのマイク", str.to_string());
}
}

0 comments on commit bb09087

Please sign in to comment.