From 40e0ccde246e7abde944ca0d88778522b9e16153 Mon Sep 17 00:00:00 2001 From: Yaroslav Bolyukin Date: Sun, 26 Apr 2026 19:28:08 +0000 Subject: [PATCH] feat: lossy base64Decode --- --- a/crates/jrsonnet-stdlib/src/encoding.rs +++ b/crates/jrsonnet-stdlib/src/encoding.rs @@ -41,9 +41,13 @@ } #[builtin] -pub fn builtin_base64_decode(str: IStr) -> Result { +pub fn builtin_base64_decode(str: IStr, #[default(false)] lossy: bool) -> Result { let bytes = STANDARD .decode(str.as_bytes()) .map_err(|e| runtime_error!("invalid base64: {e}"))?; - String::from_utf8(bytes).map_err(|_| runtime_error!("bad utf8")) + if lossy { + Ok(String::from_utf8_lossy(&bytes).to_string()) + } else { + String::from_utf8(bytes).map_err(|e| runtime_error!("bad utf8: {e}")) + } } -- gitstuff