Skip to content

Commit 7359f2b

Browse files
author
claudiamurialdo
committed
Fixed path resolution in HttpClient.ToFile for relative file names in web context
Issue:206567
1 parent aa97d0e commit 7359f2b

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

dotnet/src/dotnetframework/GxClasses/Domain/GxHttpClient.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2001,7 +2001,7 @@ public void ToFile(string fileName)
20012001
#if !NETCORE
20022002
if (HttpContext.Current != null)
20032003
#endif
2004-
if (fileName.IndexOfAny(new char[] { '\\', ':' }) == -1)
2004+
if (!Path.IsPathRooted(fileName))
20052005
pathName = Path.Combine(GxContext.StaticPhysicalPath(), fileName);
20062006

20072007
if (ReceiveData != null)

dotnet/test/DotNetUnitTest/Domain/GxHttpClientTest.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,19 @@ public void HttpClientCookiesTest()
189189

190190
}
191191

192+
[Fact]
193+
public void ToRelativeFile()
194+
{
195+
using (GxHttpClient client = new GxHttpClient())
196+
{
197+
client.Host = "localhost";
198+
client.BaseURL = "/dummy/lem.txt";
199+
client.Execute("GET", string.Empty);
200+
client.ToFile("./lem.txt");
201+
Assert.True(File.Exists(Path.Combine(Directory.GetCurrentDirectory(), "lem.txt")));
202+
}
203+
}
204+
192205
#if !NETCORE
193206
[Fact]
194207
public void NoStoreHeader()

0 commit comments

Comments
 (0)