Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add UFO dir and mandatory .plist file read path existence checks and invalid path diagnostics #143

Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,11 @@ impl Font {
}

fn load_impl(path: &Path, request: DataRequest) -> Result<Font, Error> {
if !path.exists() {
let msg = format!("invalid path: {:?}", path);
return Err(std::io::Error::new(std::io::ErrorKind::NotFound, msg).into());
}

let meta_path = path.join(METAINFO_FILE);
let mut meta: MetaInfo = plist::from_file(meta_path)?;

Expand Down Expand Up @@ -438,6 +443,14 @@ mod tests {
assert_eq!(font_obj.features.unwrap(), "# this is the feature from lightWide\n");
}

#[test]
fn loading_invalid_path() {
let path = "totally/bogus/filepath/font.ufo";
let font_obj = Font::load(path);
assert!(font_obj.is_err());
assert_eq!(format!("{:?}", font_obj), "Err(IoError(Custom { kind: NotFound, error: \"invalid path: \\\"totally/bogus/filepath/font.ufo\\\"\" }))");
}

#[test]
fn data_request() {
let path = "testdata/mutatorSans/MutatorSansLightWide.ufo";
Expand Down