From 21a44ed825249a9646004958e4f80c07e639c444 Mon Sep 17 00:00:00 2001 From: Konstantin Safonov Date: Wed, 31 Jul 2019 01:01:53 +0300 Subject: [PATCH] Allow to suppress '<' validation for attribute values --- .../Tokenizer/XmlTokenization.cs | 27 +++++++++++++++++++ src/AngleSharp.Xml/Parser/XmlTokenizer.cs | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/AngleSharp.Xml.Tests/Tokenizer/XmlTokenization.cs b/src/AngleSharp.Xml.Tests/Tokenizer/XmlTokenization.cs index 53ac3c9..54ca1ed 100644 --- a/src/AngleSharp.Xml.Tests/Tokenizer/XmlTokenization.cs +++ b/src/AngleSharp.Xml.Tests/Tokenizer/XmlTokenization.cs @@ -182,5 +182,32 @@ public void XmlTokenizerTagWithAttributeContainingEntity() Assert.AreEqual("bar", foo.Attributes[0].Key); Assert.AreEqual("\"quz\"", foo.Attributes[0].Value); } + + [Test] + public void XmlTokenizerTagThrowsWithADiamond() + { + var s = new TextSource(""); + + var t = CreateTokenizer(s); + t.IsSuppressingErrors = false; + Assert.Throws(() => t.Get()); + } + + [Test] + public void XmlTokenizerTagSuppressesWithADiamond() + { + var s = new TextSource(""); + var t = CreateTokenizer(s); + t.IsSuppressingErrors = true; + var foo = t.Get() as XmlTagToken; + + Assert.IsNotNull(foo); + Assert.AreEqual(XmlTokenType.StartTag, foo.Type); + Assert.IsFalse(foo.IsSelfClosing); + Assert.AreEqual("foo", foo.Name); + Assert.AreEqual(1, foo.Attributes.Count); + Assert.AreEqual("bar", foo.Attributes[0].Key); + Assert.AreEqual("a < b", foo.Attributes[0].Value); + } } } diff --git a/src/AngleSharp.Xml/Parser/XmlTokenizer.cs b/src/AngleSharp.Xml/Parser/XmlTokenizer.cs index ecbecc7..1d1c725 100644 --- a/src/AngleSharp.Xml/Parser/XmlTokenizer.cs +++ b/src/AngleSharp.Xml/Parser/XmlTokenizer.cs @@ -1046,7 +1046,7 @@ private XmlToken AttributeValue(XmlTagToken tag, Char quote) if (c == Symbols.EndOfFile) throw XmlParseError.EOF.At(GetCurrentPosition()); - if (c == Symbols.LessThan) + if (c == Symbols.LessThan && !IsSuppressingErrors) throw XmlParseError.XmlLtInAttributeValue.At(GetCurrentPosition()); if (c == Symbols.Ampersand)