From b871c29a857b0312b49fe9ffba01b4a303a7f1f4 Mon Sep 17 00:00:00 2001 From: Carl Johnsen Date: Wed, 28 Jan 2026 12:09:10 +0100 Subject: [PATCH] Fixed Windows paths in JSON strings --- .../RemoteSynchronizationModuleTests.cs | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/Duplicati/UnitTest/RemoteSynchronizationModuleTests.cs b/Duplicati/UnitTest/RemoteSynchronizationModuleTests.cs index 6f283bfd6..0d2584a63 100644 --- a/Duplicati/UnitTest/RemoteSynchronizationModuleTests.cs +++ b/Duplicati/UnitTest/RemoteSynchronizationModuleTests.cs @@ -52,10 +52,11 @@ namespace Duplicati.UnitTest public void Setup() { module = new RemoteSynchronizationModule(); - source = Path.Combine(TARGETFOLDER, "source"); - dest1 = Path.Combine(TARGETFOLDER, "dest1"); - dest2 = Path.Combine(TARGETFOLDER, "dest2"); - dest3 = Path.Combine(TARGETFOLDER, "dest3"); + // On Windows, we have to escape backslashes in paths for JSON strings + source = Path.Combine(TARGETFOLDER, "source").Replace("\\", "\\\\"); + dest1 = Path.Combine(TARGETFOLDER, "dest1").Replace("\\", "\\\\"); + dest2 = Path.Combine(TARGETFOLDER, "dest2").Replace("\\", "\\\\"); + dest3 = Path.Combine(TARGETFOLDER, "dest3").Replace("\\", "\\\\"); } private static void EnsureOperationTableCreated(Microsoft.Data.Sqlite.SqliteCommand cmd) @@ -81,7 +82,8 @@ namespace Duplicati.UnitTest var destinations = module.GetType().GetField("m_destinations", BINDING_FLAGS).GetValue(module) as List; Assert.AreEqual(1, destinations.Count); - Assert.AreEqual($"file://{dest1}", destinations[0].Config.Dst); + // Convert the escaped backslashes to single backslashes for comparison on Windows + Assert.AreEqual($"file://{dest1.Replace("\\\\", "\\")}", destinations[0].Config.Dst); } [Test] @@ -97,8 +99,9 @@ namespace Duplicati.UnitTest var destinations = module.GetType().GetField("m_destinations", BINDING_FLAGS).GetValue(module) as List; Assert.AreEqual(2, destinations.Count); - Assert.AreEqual($"file://{dest1}", destinations[0].Config.Dst); - Assert.AreEqual($"file://{dest2}", destinations[1].Config.Dst); + // Convert the escaped backslashes to single backslashes for comparison on Windows + Assert.AreEqual($"file://{dest1.Replace("\\\\", "\\")}", destinations[0].Config.Dst); + Assert.AreEqual($"file://{dest2.Replace("\\\\", "\\")}", destinations[1].Config.Dst); } [Test] @@ -963,8 +966,9 @@ namespace Duplicati.UnitTest var destinations = module.GetType().GetField("m_destinations", BINDING_FLAGS).GetValue(module) as List; Assert.AreEqual(2, destinations.Count); - Assert.AreEqual($" file://{dest1} ", destinations[0].Config.Dst); // JSON preserves spaces - Assert.AreEqual($" file://{dest2} ", destinations[1].Config.Dst); + // Convert the escaped backslashes to single backslashes for comparison on Windows + Assert.AreEqual($" file://{dest1.Replace("\\\\", "\\")} ", destinations[0].Config.Dst); + Assert.AreEqual($" file://{dest2.Replace("\\\\", "\\")} ", destinations[1].Config.Dst); } [Test] @@ -980,9 +984,10 @@ namespace Duplicati.UnitTest var destinations = module.GetType().GetField("m_destinations", BINDING_FLAGS).GetValue(module) as List; Assert.AreEqual(3, destinations.Count); // All are included, empty ones skipped in OnFinish - Assert.AreEqual($"file://{dest1}", destinations[0].Config.Dst); + // Convert the escaped backslashes to single backslashes for comparison on Windows + Assert.AreEqual($"file://{dest1.Replace("\\\\", "\\")}", destinations[0].Config.Dst); Assert.AreEqual("", destinations[1].Config.Dst); - Assert.AreEqual($"file://{dest2}", destinations[2].Config.Dst); + Assert.AreEqual($"file://{dest2.Replace("\\\\", "\\")}", destinations[2].Config.Dst); } [Test]