PdfCraft: An open-source PDF reader and editor written by scratch in pure Rust
Reject '+' as a hex digit in FormCalc url Decode escapes (#4586)
NetterSilver4f9b16fa1412
diff --git a/crates/js/src/formcalc.rs b/crates/js/src/formcalc.rsindex 7b0d0e88a..5e7bb65fa 100644--- a/crates/js/src/formcalc.rs+++ b/crates/js/src/formcalc.rs@@ -2278,8 +2278,11 @@ impl Interp<'_> {let mut i = 0;while i < b.len() {if b[i] == b'%'- && let Some(h) =- b.get(i + 1..i + 3).and_then(|h| std::str::from_utf8(h).ok()).and_then(|h| u8::from_str_radix(h, 16).ok())+ && let Some(h) = b+ .get(i + 1..i + 3)+ .filter(|h| h.iter().all(u8::is_ascii_hexdigit))+ .and_then(|h| std::str::from_utf8(h).ok())+ .and_then(|h| u8::from_str_radix(h, 16).ok()){out.push(h);i += 3;diff --git a/crates/js/src/tests.rs b/crates/js/src/tests.rsindex 3d3c4ab52..748ce038d 100644--- a/crates/js/src/tests.rs+++ b/crates/js/src/tests.rs@@ -1012,6 +1012,8 @@ mod formcalc {#[test]fn built_in_functions_cover_the_common_set() {assert_eq!(calc("Abs(-2.5)"), "2.5");+ assert_eq!(calc(r#"Decode("a%2Fb", "url")"#), "a/b");+ assert_eq!(calc(r#"Decode("a%+fb", "url")"#), "a%+fb");assert_eq!(calc("Ceil(2.1)"), "3");assert_eq!(calc("Floor(-2.1)"), "-3");assert_eq!(calc("Mod(7, 3)"), "1");