mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-10-27 11:37:59 -06:00
XFDF: gracefully ignore invalid Unicode annotation colours (#48)
Use checked string slices when reading annotation colour components. Cover colour and interior-colour imports with a synthetic XFDF regression. Co-authored-by: storybored379 <storybored379@users.noreply.github.com> Co-authored-by: OpenAI Codex <noreply@openai.com>
This commit is contained in:
co-authored by
storybored379
OpenAI Codex
parent
0447a0fc7b
commit
890ae8d3ed
@@ -140,7 +140,7 @@ fn parse_hex(s: &str) -> Option<[f64; 3]> {
|
||||
if h.len() != 6 {
|
||||
return None;
|
||||
}
|
||||
let p = |i: usize| u8::from_str_radix(&h[i..i + 2], 16).ok().map(|v| f64::from(v) / 255.0);
|
||||
let p = |i: usize| h.get(i..i + 2).and_then(|s| u8::from_str_radix(s, 16).ok()).map(|v| f64::from(v) / 255.0);
|
||||
Some([p(0)?, p(2)?, p(4)?])
|
||||
}
|
||||
|
||||
|
||||
@@ -204,3 +204,15 @@ fn data_files_merge_into_a_spreadsheet() {
|
||||
assert!(lines[3].starts_with("\"Grace \"\"Amazing\"\" Hopper, RADM\",Off,"), "{csv}");
|
||||
assert_eq!(data_values(b"not data"), Err(DataError::UnknownFormat));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unicode_annotation_colours_are_ignored_without_panicking() {
|
||||
for attr in ["color", "interior-color"] {
|
||||
let mut doc = blank();
|
||||
let xml = format!(
|
||||
r##"<xfdf xmlns="http://ns.adobe.com/xfdf/"><annots><square page="0" rect="10,10,50,50" name="unicode-colour" {attr}="#€€" /></annots></xfdf>"##
|
||||
);
|
||||
let report = import(&mut doc, xml.as_bytes()).unwrap();
|
||||
assert_eq!(report.comments, 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user