difftreelog
feat lossy base64Decode
in: master
1 file changed
crates/jrsonnet-stdlib/src/encoding.rsdiffbeforeafterboth41}41}424243#[builtin]43#[builtin]44pub fn builtin_base64_decode(str: IStr) -> Result<String> {44pub fn builtin_base64_decode(str: IStr, #[default(false)] lossy: bool) -> Result<String> {45 let bytes = STANDARD45 let bytes = STANDARD46 .decode(str.as_bytes())46 .decode(str.as_bytes())47 .map_err(|e| runtime_error!("invalid base64: {e}"))?;47 .map_err(|e| runtime_error!("invalid base64: {e}"))?;48 if lossy {49 Ok(String::from_utf8_lossy(&bytes).to_string())50 } else {48 String::from_utf8(bytes).map_err(|_| runtime_error!("bad utf8"))51 String::from_utf8(bytes).map_err(|e| runtime_error!("bad utf8: {e}"))52 }49}53}5054