Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ thiserror = "2.0"
indexmap = { version = "2.0.0", features = ["serde"] }
base64 = "0.22"
close_already = "0.3"
log = "0.4"

[dev-dependencies]
failure = "0.1.6"
Expand Down
18 changes: 13 additions & 5 deletions src/glyph/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -308,12 +308,20 @@ impl<'names> GlifParser<'names> {
}

let plist_slice = &raw_xml[start..end];
let dict = plist::Value::from_reader_xml(plist_slice)
.map_err(|_| GlifLoadError::Parse(ErrorKind::BadLib))?
.into_dictionary()
.ok_or(GlifLoadError::Parse(ErrorKind::LibMustBeDictionary))?;
match plist::Value::from_reader_xml(plist_slice)
.map_err(|_| GlifLoadError::Parse(ErrorKind::BadLib))
.and_then(|x| {
x.into_dictionary().ok_or(GlifLoadError::Parse(ErrorKind::LibMustBeDictionary))
}) {
Ok(dict) => {
// we used to error if this was malformed but there are a number of early UFO files
// in the wild that store arbitrary xml in the lib, which doesn't parse as a plist.
// Instead of failing to parse these files, we prefer to just skip the dicts.
self.glyph.lib = dict;
}
Err(e) => log::info!("glyph {} contains invalid lib: '{e}'", self.glyph.name),
}

self.glyph.lib = dict;
Ok(())
}

Expand Down
8 changes: 5 additions & 3 deletions src/glyph/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,9 @@ fn bad_angle() {
}

#[test]
#[should_panic(expected = "LibMustBeDictionary")]
fn lib_must_be_dict() {
// in a number of older UFO files in the wild glyphs can contain dictionaries
// with arbitrary non-plsit XML:
fn skip_non_lib_dictionary() {
let data = r#"
<?xml version="1.0" encoding="UTF-8"?>
<glyph name="period" format="2">
Expand All @@ -328,7 +329,8 @@ fn lib_must_be_dict() {
</lib>
</glyph>
"#;
let _ = parse_glyph(data.as_bytes()).unwrap();
let glyph = parse_glyph(data.as_bytes()).unwrap();
assert!(glyph.lib.is_empty());
}

#[test]
Expand Down