From a38c84eb2564b6488d3ec4fcf3043175a3ee20dd Mon Sep 17 00:00:00 2001 From: cmurialdo Date: Wed, 30 Nov 2022 12:27:46 -0300 Subject: [PATCH 1/2] Fix for AddPath on linux --- .../src/dotnetframework/GxClasses/Printer/GxPrinter.cs | 2 +- dotnet/test/DotNetUnitTest/FileIO/FileIOTests.cs | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/dotnet/src/dotnetframework/GxClasses/Printer/GxPrinter.cs b/dotnet/src/dotnetframework/GxClasses/Printer/GxPrinter.cs index 70b560aed..00d2b74a4 100644 --- a/dotnet/src/dotnetframework/GxClasses/Printer/GxPrinter.cs +++ b/dotnet/src/dotnetframework/GxClasses/Printer/GxPrinter.cs @@ -2139,7 +2139,7 @@ public class ReportUtils { static public string AddPath(string name, string path) { - if( name.IndexOf(":") != -1 || + if (Path.IsPathRooted(name) || name.IndexOf(":") != -1 || (name.Length >=2 && (name.Substring( 0,2) == "//" || name.Substring( 0,2) == @"\\")) || (name.StartsWith("http:" ) || name.StartsWith("https:" ))) return name; diff --git a/dotnet/test/DotNetUnitTest/FileIO/FileIOTests.cs b/dotnet/test/DotNetUnitTest/FileIO/FileIOTests.cs index a8cab65c2..0cec6803a 100644 --- a/dotnet/test/DotNetUnitTest/FileIO/FileIOTests.cs +++ b/dotnet/test/DotNetUnitTest/FileIO/FileIOTests.cs @@ -1,6 +1,7 @@ using System; using System.IO; using GeneXus.Configuration; +using GeneXus.Printer; using GeneXus.Utils; using Xunit; @@ -89,5 +90,14 @@ public void PathUtilGetValidFileName() fileName = PathUtil.GetValidFileName(path, "_"); Assert.StartsWith("Screen Shot 2016-02-15 at 11.41.55 AM", fileName, StringComparison.OrdinalIgnoreCase); } + + [Fact] + public void ReportUtilAddPath() + { + string name = "/mnt/c/Models/DockerReport/NETModel/Web/PublicTempStorage/clientreportebee6af4-7554-4283-b246-e1600e49b103.pdf"; + string path = "/mnt/c/Models/DockerReport/NETModel/Web/"; + string fullPath = ReportUtils.AddPath(name, path); + Assert.Equal(name, fullPath); + } } } From a2a87107a27ae1f552824fb36d2e47bf5af94c36 Mon Sep 17 00:00:00 2001 From: cmurialdo Date: Wed, 30 Nov 2022 13:11:54 -0300 Subject: [PATCH 2/2] Add more cases for ReportUtils.AddPath --- .../GxClasses/Printer/GxPrinter.cs | 2 +- .../test/DotNetUnitTest/FileIO/FileIOTests.cs | 20 ++++++++++++++++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/dotnet/src/dotnetframework/GxClasses/Printer/GxPrinter.cs b/dotnet/src/dotnetframework/GxClasses/Printer/GxPrinter.cs index 00d2b74a4..f3b8dd6cd 100644 --- a/dotnet/src/dotnetframework/GxClasses/Printer/GxPrinter.cs +++ b/dotnet/src/dotnetframework/GxClasses/Printer/GxPrinter.cs @@ -2143,7 +2143,7 @@ static public string AddPath(string name, string path) (name.Length >=2 && (name.Substring( 0,2) == "//" || name.Substring( 0,2) == @"\\")) || (name.StartsWith("http:" ) || name.StartsWith("https:" ))) return name; - return path + name; + return Path.Combine(path, name); } } diff --git a/dotnet/test/DotNetUnitTest/FileIO/FileIOTests.cs b/dotnet/test/DotNetUnitTest/FileIO/FileIOTests.cs index 0cec6803a..28decb1d7 100644 --- a/dotnet/test/DotNetUnitTest/FileIO/FileIOTests.cs +++ b/dotnet/test/DotNetUnitTest/FileIO/FileIOTests.cs @@ -92,12 +92,30 @@ public void PathUtilGetValidFileName() } [Fact] - public void ReportUtilAddPath() + public void ReportUtilAddPathLinux() { string name = "/mnt/c/Models/DockerReport/NETModel/Web/PublicTempStorage/clientreportebee6af4-7554-4283-b246-e1600e49b103.pdf"; string path = "/mnt/c/Models/DockerReport/NETModel/Web/"; string fullPath = ReportUtils.AddPath(name, path); Assert.Equal(name, fullPath); } + + [Fact] + public void ReportUtilAddPathWindows() + { + string name = "PublicTempStorage/clientreportebee6af4-7554-4283-b246-e1600e49b103.pdf"; + string path = "C:/Models/Report/NETModel/Web/"; + string fullPath = ReportUtils.AddPath(name, path); + + Assert.Equal(Path.Combine(path, name), fullPath); + } + [Fact] + public void ReportUtilAddPathHttp() + { + string name = "http://localhost:5000/WebApp/PublicTempStorage/clientreportebee6af4-7554-4283-b246-e1600e49b103.pdf"; + string path = "C:/Models/Report/NETModel/Web/"; + string fullPath = ReportUtils.AddPath(name, path); + Assert.Equal(name, fullPath); + } } }