diff --git a/src/HtmlAgilityPack.Shared/HtmlDocument.cs b/src/HtmlAgilityPack.Shared/HtmlDocument.cs
index d97fa23d..32656b80 100644
--- a/src/HtmlAgilityPack.Shared/HtmlDocument.cs
+++ b/src/HtmlAgilityPack.Shared/HtmlDocument.cs
@@ -1867,7 +1867,7 @@ private void PushAttributeNameStart(int index, int lineposition)
_currentattribute.Line = _line;
_currentattribute._lineposition = lineposition;
_currentattribute._streamposition = index;
- _currentattribute.InternalQuoteType = AttributeValueQuote.WithoutValue;
+ //_currentattribute.InternalQuoteType = AttributeValueQuote.WithoutValue;
}
private void PushAttributeValueEnd(int index)
diff --git a/src/HtmlAgilityPack.Shared/HtmlNode.cs b/src/HtmlAgilityPack.Shared/HtmlNode.cs
index dd4ce703..c8dfd7c4 100644
--- a/src/HtmlAgilityPack.Shared/HtmlNode.cs
+++ b/src/HtmlAgilityPack.Shared/HtmlNode.cs
@@ -2415,7 +2415,24 @@ internal void WriteAttribute(TextWriter outText, HtmlAttribute att)
var isWithoutValue = quoteType == AttributeValueQuote.WithoutValue;
string name;
- string quote = quoteType == AttributeValueQuote.DoubleQuote ? "\"" : quoteType == AttributeValueQuote.SingleQuote ? "'" : "";
+ string quote;
+ switch (quoteType)
+ {
+ case AttributeValueQuote.DoubleQuote:
+ case AttributeValueQuote.Initial:
+ case AttributeValueQuote.WithoutValue:
+ quote = "\"";
+ break;
+ case AttributeValueQuote.SingleQuote:
+ quote = "'";
+ break;
+ case AttributeValueQuote.None:
+ default:
+ quote = "";
+ break;
+ }
+
+
if (_ownerdocument.OptionOutputAsXml)
{
if(quoteType != AttributeValueQuote.DoubleQuote && quoteType != AttributeValueQuote.SingleQuote)
@@ -2457,24 +2474,26 @@ internal void WriteAttribute(TextWriter outText, HtmlAttribute att)
}
}
- if (!isWithoutValue)
- {
- var value = quoteType == AttributeValueQuote.DoubleQuote ? !att.Value.StartsWith("@") ? att.Value.Replace("\"", """) :
- att.Value : quoteType == AttributeValueQuote.SingleQuote ? att.Value.Replace("'", "'") : att.Value;
- if (_ownerdocument.OptionOutputOptimizeAttributeValues)
- if (att.Value.IndexOfAny(new char[] {(char) 10, (char) 13, (char) 9, ' '}) < 0)
- outText.Write(" " + name + "=" + att.Value);
- else
- outText.Write(" " + name + "=" + quote + value + quote);
- else
- outText.Write(" " + name + "=" + quote + value + quote);
- }
- else
+ if (isWithoutValue)
{
- outText.Write(" " + name);
- }
-
- }
+ outText.Write(" " + name);
+ }
+ else
+ {
+ var value = quoteType == AttributeValueQuote.DoubleQuote
+ ? !att.Value.StartsWith("@") ? att.Value.Replace("\"", """) : att.Value
+ : quoteType == AttributeValueQuote.SingleQuote
+ ? att.Value.Replace("'", "'")
+ : att.Value;
+ if (_ownerdocument.OptionOutputOptimizeAttributeValues)
+ if (att.Value.IndexOfAny(new char[] { (char)10, (char)13, (char)9, ' ' }) < 0)
+ outText.Write(" " + name + "=" + att.Value);
+ else
+ outText.Write(" " + name + "=" + quote + value + quote);
+ else
+ outText.Write(" " + name + "=" + quote + value + quote);
+ }
+ }
}
internal void WriteAttributes(TextWriter outText, bool closing)
diff --git a/src/Tests/HtmlAgilityPack.Tests.NetStandard2_0/HtmlDocument.PreserveOriginalTest.cs b/src/Tests/HtmlAgilityPack.Tests.NetStandard2_0/HtmlDocument.PreserveOriginalTest.cs
index 02ead6fa..fdd37ae1 100644
--- a/src/Tests/HtmlAgilityPack.Tests.NetStandard2_0/HtmlDocument.PreserveOriginalTest.cs
+++ b/src/Tests/HtmlAgilityPack.Tests.NetStandard2_0/HtmlDocument.PreserveOriginalTest.cs
@@ -161,6 +161,31 @@ public void PreserveClonedEmptyAttributesTest()
Assert.Equal(@"