From 7359f2bb29f6b15988fa45258652b70a15c7fc31 Mon Sep 17 00:00:00 2001 From: claudiamurialdo Date: Mon, 6 Oct 2025 11:04:38 -0300 Subject: [PATCH 1/2] Fixed path resolution in HttpClient.ToFile for relative file names in web context Issue:206567 --- .../GxClasses/Domain/GxHttpClient.cs | 2 +- .../test/DotNetUnitTest/Domain/GxHttpClientTest.cs | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/dotnet/src/dotnetframework/GxClasses/Domain/GxHttpClient.cs b/dotnet/src/dotnetframework/GxClasses/Domain/GxHttpClient.cs index 62e3de2c0..44a58360f 100644 --- a/dotnet/src/dotnetframework/GxClasses/Domain/GxHttpClient.cs +++ b/dotnet/src/dotnetframework/GxClasses/Domain/GxHttpClient.cs @@ -2001,7 +2001,7 @@ public void ToFile(string fileName) #if !NETCORE if (HttpContext.Current != null) #endif - if (fileName.IndexOfAny(new char[] { '\\', ':' }) == -1) + if (!Path.IsPathRooted(fileName)) pathName = Path.Combine(GxContext.StaticPhysicalPath(), fileName); if (ReceiveData != null) diff --git a/dotnet/test/DotNetUnitTest/Domain/GxHttpClientTest.cs b/dotnet/test/DotNetUnitTest/Domain/GxHttpClientTest.cs index 152ebfa6b..adf58a262 100644 --- a/dotnet/test/DotNetUnitTest/Domain/GxHttpClientTest.cs +++ b/dotnet/test/DotNetUnitTest/Domain/GxHttpClientTest.cs @@ -189,6 +189,19 @@ public void HttpClientCookiesTest() } + [Fact] + public void ToRelativeFile() + { + using (GxHttpClient client = new GxHttpClient()) + { + client.Host = "localhost"; + client.BaseURL = "/dummy/lem.txt"; + client.Execute("GET", string.Empty); + client.ToFile("./lem.txt"); + Assert.True(File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "lem.txt"))); + } + } + #if !NETCORE [Fact] public void NoStoreHeader() From 6f46e524742e5c1b72123f6d0f8e8eca88ff503f Mon Sep 17 00:00:00 2001 From: claudiamurialdo <33756655+claudiamurialdo@users.noreply.github.com> Date: Mon, 27 Oct 2025 17:37:57 -0300 Subject: [PATCH 2/2] Change file existence check in GxHttpClientTest Updated file existence assertion to use GxContext.StaticPhysicalPath. --- dotnet/test/DotNetUnitTest/Domain/GxHttpClientTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dotnet/test/DotNetUnitTest/Domain/GxHttpClientTest.cs b/dotnet/test/DotNetUnitTest/Domain/GxHttpClientTest.cs index adf58a262..cadf70508 100644 --- a/dotnet/test/DotNetUnitTest/Domain/GxHttpClientTest.cs +++ b/dotnet/test/DotNetUnitTest/Domain/GxHttpClientTest.cs @@ -198,7 +198,7 @@ public void ToRelativeFile() client.BaseURL = "/dummy/lem.txt"; client.Execute("GET", string.Empty); client.ToFile("./lem.txt"); - Assert.True(File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "lem.txt"))); + Assert.True(File.Exists(Path.Combine(GxContext.StaticPhysicalPath(), "lem.txt")), $"HttpClient.ToFile failed to create the file at path: {GxContext.StaticPhysicalPath()}"); } }