Commit 95b3850f authored by Tebjan Halm's avatar Tebjan Halm
Browse files

Merge pull request #226 from AnkHansen/225-ImageTag-fails-if-Uri-too-large

Issue 225 - Image with large embedded image fails to render
parents 32319fd1 a0da74b0
......@@ -74,9 +74,9 @@ namespace Svg
}
[SvgAttribute("href", SvgAttributeAttribute.XLinkNamespace)]
public virtual Uri Href
public virtual string Href
{
get { return this.Attributes.GetAttribute<Uri>("href"); }
get { return this.Attributes.GetAttribute<string>("href"); }
set { this.Attributes["href"] = value; }
}
......@@ -232,14 +232,15 @@ namespace Svg
}
}
protected object GetImage(Uri uri)
protected object GetImage(string uriString)
{
try
{
var uri = new Uri(uriString.Substring(0, 65519)); //Uri MaxLength is 65519 (https://msdn.microsoft.com/en-us/library/z6c2z492.aspx)
// handle data/uri embedded images (http://en.wikipedia.org/wiki/Data_URI_scheme)
if (uri.IsAbsoluteUri && uri.Scheme == "data")
{
string uriString = uri.OriginalString;
int dataIdx = uriString.IndexOf(",") + 1;
if (dataIdx <= 0 || dataIdx + 1 > uriString.Length)
throw new Exception("Invalid data URI");
......@@ -284,7 +285,7 @@ namespace Svg
}
catch (Exception ex)
{
Trace.TraceError("Error loading image: '{0}', error: {1} ", uri, ex.Message);
Trace.TraceError("Error loading image: '{0}', error: {1} ", uriString, ex.Message);
return null;
}
}
......
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Svg.DataTypes;
using System;
using System.Diagnostics;
using System.Drawing;
using System.IO;
namespace Svg.UnitTests
{
/// <summary>
/// Test Class of rendering SVGs with a large embedded image
/// Based on Issue 225
/// </summary>
/// <remarks>
/// Test use the following embedded resources:
/// - Issue225_LargeUri\Speedometer.svg
/// </remarks>
[TestClass]
public class LargeEmbeddedImageTest : SvgTestHelper
{
protected override string TestResource { get { return GetFullResourceString("Issue225_LargeUri.Speedometer.svg"); } }
protected override int ExpectedSize { get { return 160000; } }
[TestMethod]
public void TestImageIsRendered()
{
LoadSvg(GetXMLDocFromResource());
}
}
}
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -55,6 +55,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="CssQueryTest.cs" />
<Compile Include="LargeEmbeddedImageTest.cs" />
<Compile Include="MarkerEndTest.cs" />
<Compile Include="MetafileRenderingTest.cs" />
<Compile Include="MultiThreadingTest.cs" />
......@@ -81,6 +82,9 @@
<ItemGroup>
<EmbeddedResource Include="Resources\Issue212_MakerEnd\OperatingPlan.svg" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\Issue225_LargeUri\Speedometer.svg" />
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment