Skip to content

Commit

Permalink
Fix issue with invalid chars in an image source
Browse files Browse the repository at this point in the history
  • Loading branch information
Kees committed Aug 28, 2019
1 parent 45b8445 commit 6902692
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 4 deletions.
1 change: 1 addition & 0 deletions ChromeHtmlToPdfLib/ChromeHtmlToPdfLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
<Compile Include="Helpers\ExceptionHelper.cs" />
<Compile Include="Helpers\Extensions.cs" />
<Compile Include="Helpers\DocumentHelper.cs" />
<Compile Include="Helpers\FileManager.cs" />
<Compile Include="Helpers\Logger.cs" />
<Compile Include="Helpers\PreWrapper.cs" />
<Compile Include="Helpers\Sanitizer\EventArgs.cs" />
Expand Down
7 changes: 5 additions & 2 deletions ChromeHtmlToPdfLib/Helpers/DocumentHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -195,9 +195,12 @@ public bool Validate(ConvertUri inputUri,
}

Image image = null;
var extension = Path.GetExtension(htmlImage.Source.Contains("?")
var source = htmlImage.Source.Contains("?")
? htmlImage.Source.Split('?')[0]
: htmlImage.Source);
: htmlImage.Source;

var extension = Path.GetExtension(FileManager.RemoveInvalidFileNameChars(source));

var fileName = GetTempFile(extension);

try
Expand Down
22 changes: 22 additions & 0 deletions ChromeHtmlToPdfLib/Helpers/FileManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
using System.Globalization;
using System.IO;
using System.Linq;

namespace ChromeHtmlToPdfLib.Helpers
{
internal static class FileManager
{
#region RemoveInvalidFileNameChars
/// <summary>
/// Verwijdert illegale karakters uit een bestandsnaam
/// </summary>
/// <param name="fileName"></param>
/// <returns></returns>
public static string RemoveInvalidFileNameChars(string fileName)
{
return Path.GetInvalidFileNameChars()
.Aggregate(fileName, (current, c) => current.Replace(c.ToString(CultureInfo.InvariantCulture), string.Empty));
}
#endregion
}
}
4 changes: 2 additions & 2 deletions ChromeHtmlToPdfLib/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.4.2.0")]
[assembly: AssemblyFileVersion("1.4.2.0")]
[assembly: AssemblyVersion("1.4.4.0")]
[assembly: AssemblyFileVersion("1.4.4.0")]

0 comments on commit 6902692

Please sign in to comment.