From 5001a0e37d0e828b8705faf215c0d4357dab9d5e Mon Sep 17 00:00:00 2001 From: Floris Bruynooghe Date: Fri, 20 Sep 2019 17:46:21 +0200 Subject: [PATCH] Fix dc_make_rel_path This was not substituting $BLOBDIR correctly. --- src/dc_tools.rs | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/dc_tools.rs b/src/dc_tools.rs index 3d79084bd..1c42acd40 100644 --- a/src/dc_tools.rs +++ b/src/dc_tools.rs @@ -895,7 +895,7 @@ fn dc_make_rel_path(context: &Context, path: &mut String) { .map(|s| path.starts_with(s)) .unwrap_or_default() { - *path = path.replace("$BLOBDIR", context.get_blobdir().to_str().unwrap()); + *path = path.replace(context.get_blobdir().to_str().unwrap(), "$BLOBDIR"); } } @@ -1246,8 +1246,11 @@ pub fn listflags_has(listflags: u32, bitindex: usize) -> bool { #[cfg(test)] mod tests { use super::*; + use std::ffi::CStr; + use crate::test_utils::*; + #[test] fn test_dc_strdup() { unsafe { @@ -1792,4 +1795,17 @@ mod tests { let res = dc_create_incoming_rfc724_mid(123, 45, &vec![6, 7]); assert_eq!(res, Some("123-45-7@stub".into())); } + + #[test] + fn test_dc_make_rel_path() { + let t = dummy_context(); + let mut foo: String = t + .ctx + .get_blobdir() + .join("foo") + .to_string_lossy() + .into_owned(); + dc_make_rel_path(&t.ctx, &mut foo); + assert_eq!(foo, format!("$BLOBDIR{}foo", std::path::MAIN_SEPARATOR)); + } }