Skip to content

Commit 320651f

Browse files
Fix error "System.ArgumentException: Illegal characters in path" when adding an image from URL to report.
Path.IsPathRooted validates the path for valid charactersPath (only in .NET Framework)
1 parent cb5abed commit 320651f

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

dotnet/src/dotnetframework/GxClasses/Printer/GxPrinter.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ namespace GeneXus.Printer
1616
using System.Threading;
1717
using System.Threading.Tasks;
1818
using GeneXus.Configuration;
19+
using GeneXus.Utils;
1920
using GeneXus.XML;
2021

2122
public interface IPrintHandler
@@ -2162,10 +2163,19 @@ public class ReportUtils
21622163
{
21632164
static public string AddPath(string name, string path)
21642165
{
2165-
if (Path.IsPathRooted(name) || name.IndexOf(":") != -1 ||
2166+
if (name.IndexOf(":") != -1 ||
21662167
(name.Length >=2 && (name.Substring( 0,2) == "//" || name.Substring( 0,2) == @"\\")) ||
21672168
(name.StartsWith("http:" ) || name.StartsWith("https:" )))
21682169
return name;
2170+
#if NETCORE
2171+
if (Path.IsPathRooted (name))
2172+
return name;
2173+
#else
2174+
if (PathUtil.IsValidFilePath(name) && Path.IsPathRooted(name))
2175+
{
2176+
return name;
2177+
}
2178+
#endif
21692179
return Path.Combine(path, name);
21702180
}
21712181
}

dotnet/test/DotNetUnitTest/FileIO/FileIOTests.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,5 +117,15 @@ public void ReportUtilAddPathHttp()
117117
string fullPath = ReportUtils.AddPath(name, path);
118118
Assert.Equal(name, fullPath);
119119
}
120+
[Fact]
121+
public void ReportUtilAddPathWithIllegalCharacters()
122+
{
123+
string name = "https://chart.googleapis.com/chart?chs=400x400&cht=qr&chl=http://sistemas.gov/nfceweb/consultarNFCe.jsp?p=13231205514674000128650020009504049878593990|2|1|09|1337.07|4558626967746769617A304E4B7A6D34504B4E61524A474F4D32513D|1|14D0A30916C6C7EA709E7E33E330EE3F290FE25D";
124+
string path = "C:/Models/Report/NETModel/Web/";
125+
string fullPath = ReportUtils.AddPath(name, path);
126+
127+
Assert.Equal(name, fullPath);
128+
}
129+
120130
}
121131
}

0 commit comments

Comments
 (0)