From f7ef6b33850dbe63a085117f69c4f18bc75ede8c Mon Sep 17 00:00:00 2001 From: brunocapelao Date: Tue, 6 Jan 2026 10:01:46 -0300 Subject: [PATCH] fix: hex_or_base64 digit recognition The is_ascii_lowercase() method returns false for digits (0-9), causing valid lowercase hex strings like '0a1b2c3d' to be incorrectly parsed as base64 instead of hex. This fix uses explicit pattern matching for valid lowercase hex characters (0-9, a-f) to correctly identify hex-encoded strings. --- src/lib.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index f86b934..fbc8341 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -57,7 +57,9 @@ pub trait GetInfo { /// An even-length string with exclusively lowercase hex characters will be parsed as hex; /// failing that, it will be parsed as base64 and return an error accordingly. pub fn hex_or_base64(s: &str) -> Result, simplicity::base64::DecodeError> { - if s.len() % 2 == 0 && s.bytes().all(|b| b.is_ascii_hexdigit() && b.is_ascii_lowercase()) { + // Use explicit matching for lowercase hex (0-9, a-f) since is_ascii_lowercase() + // returns false for digits, causing valid hex strings to be parsed as base64 + if s.len() % 2 == 0 && s.bytes().all(|b| matches!(b, b'0'..=b'9' | b'a'..=b'f')) { use simplicity::hex::FromHex as _; Ok(Vec::from_hex(s).expect("charset checked above")) } else {