From 2bbd3bd4240b23d581bc7f5b8b2703d5155af631 Mon Sep 17 00:00:00 2001 From: Vincent Prouillet Date: Sun, 21 Feb 2021 09:09:02 +0100 Subject: [PATCH] Fix compute_hash --- components/templates/src/global_fns/mod.rs | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/components/templates/src/global_fns/mod.rs b/components/templates/src/global_fns/mod.rs index 42b2cbf9..b0c98b9f 100644 --- a/components/templates/src/global_fns/mod.rs +++ b/components/templates/src/global_fns/mod.rs @@ -100,11 +100,10 @@ where { let mut hasher = D::new(); io::copy(&mut file, &mut hasher)?; - let val = format!("{:x}", hasher.finalize()); if base64 { - Ok(encode_b64(val)) + Ok(format!("{}", encode_b64(hasher.finalize()))) } else { - Ok(val) + Ok(format!("{:x}", hasher.finalize())) } } @@ -206,7 +205,7 @@ impl TeraFn for GetFileHash { let f = match open_file(&self.search_paths, &path) { Ok(f) => f, Err(e) => { - return Err(format!("File {} could not be open {}", path, e).into()); + return Err(format!("File {} could not be open: {} (searched in {:?})", path, e, self.search_paths).into()); } }; @@ -897,12 +896,9 @@ title = "A title" let static_fn = GetFileHash::new(vec![TEST_CONTEXT.static_path.clone()]); let mut args = HashMap::new(); args.insert("path".to_string(), to_value("doesnt-exist").unwrap()); - assert_eq!( - format!( - "file `doesnt-exist` not found; searched in {}", - TEST_CONTEXT.static_path.to_str().unwrap() - ), - format!("{}", static_fn.call(&args).unwrap_err()) - ); + let err = format!("{}", static_fn.call(&args).unwrap_err()); + println!("{:?}", err); + + assert!(err.contains("File doesnt-exist could not be open")); } }