[SVGPreview]Handle comments properly (#28863)

* [SVGPreview] Handle comments properly

* f: spelling

* f: add tolerance to the bitmap eq test

* f: remove bitmap eq testing, since it doesn't work on CI for some reason

* f: parsing issue
This commit is contained in:
Andrey Nekrasov
2023-10-02 22:42:31 +02:00
committed by GitHub
parent 11f30f9d33
commit e14ff34b37
5 changed files with 47 additions and 12 deletions

View File

@@ -119,7 +119,7 @@ namespace Common.Utilities
while ((index = s.IndexOf('<', index)) != -1)
{
if (index < s.Length - 1 && s[index + 1] != '?')
if (index < s.Length - 1 && s[index + 1] != '?' && s[index + 1] != '!')
{
return index;
}
@@ -130,11 +130,11 @@ namespace Common.Utilities
return -1;
}
private static int FindFirstXmlCloseTagIndex(string s)
private static int FindFirstXmlCloseTagIndex(string s, int openTagIndex)
{
int index = 1;
while ((index = s.IndexOf('>', index)) != -1)
while ((index = s.IndexOf('>', openTagIndex)) != -1)
{
if (index > 0 && s[index - 1] != '?')
{
@@ -160,7 +160,7 @@ namespace Common.Utilities
return stringSvgData;
}
int firstXmlCloseTagIndex = FindFirstXmlCloseTagIndex(stringSvgData);
int firstXmlCloseTagIndex = FindFirstXmlCloseTagIndex(stringSvgData, firstXmlOpenTagIndex);
if (firstXmlCloseTagIndex == -1)
{
return stringSvgData;
@@ -192,13 +192,18 @@ namespace Common.Utilities
styleIndex -= numRemoved;
}
firstXmlCloseTagIndex -= numRemoved;
stringSvgData = RemoveAttribute(stringSvgData, heightIndex, HeightAttribute, out numRemoved);
if (styleIndex != -1 && styleIndex > heightIndex)
{
styleIndex -= numRemoved;
}
firstXmlCloseTagIndex -= numRemoved;
stringSvgData = RemoveAttribute(stringSvgData, styleIndex, StyleAttribute, out numRemoved);
firstXmlCloseTagIndex -= numRemoved;
width = CheckUnit(width);
height = CheckUnit(height);
@@ -213,7 +218,7 @@ namespace Common.Utilities
scaling += $" _height:expression(this.scrollHeight &gt; {heightR} ? &quot; {height}&quot; : &quot;auto&quot;); _width:expression(this.scrollWidth &gt; {widthR} ? &quot;{width}&quot; : &quot;auto&quot;);";
string newStyle = $"style=\"{scaling}{centering}{oldStyle}\"";
int insertAt = stringSvgData.IndexOf(">", StringComparison.InvariantCultureIgnoreCase);
int insertAt = firstXmlCloseTagIndex;
stringSvgData = stringSvgData.Insert(insertAt, " " + newStyle);