Skip to content

[generator] Fix for fixing invalid annotation XML. #897

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 26, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ static Stream FixAnnotationXML (Stream s)
if (doc.DocumentNode.FirstChild.InnerHtml.StartsWith ("<?xml", StringComparison.Ordinal))
doc.DocumentNode.FirstChild.Remove ();

FixEscapedQuotes (doc.DocumentNode);

var ms = new MemoryStream ();
var xs = new XmlWriterSettings {
Encoding = new UTF8Encoding (false),
Expand All @@ -86,6 +88,18 @@ static Stream FixAnnotationXML (Stream s)
return ms;
}

static void FixEscapedQuotes (HtmlNode node)
{
// Quotation marks in attribute values are already escaped as '&quot;', however the Save ()
// is interpreting them as the string '&quot;' and thinks it needs to escape the ampersand,
// resulting in writing '&amp;quot;'. Here we "un-escape" the quotation mark,
// so that Save () will escape it correctly as '&quot;'.
foreach (var attr in node.Attributes)
attr.Value = attr.Value.Replace ("&quot;", "\"");

foreach (var child in node.ChildNodes)
FixEscapedQuotes (child);
}
#endregion

#region data loader
Expand Down