Skip to content

Commit

Permalink
Merge pull request #7 from kasthack/feature/issues-6-allow-diamond-br…
Browse files Browse the repository at this point in the history
…acket-in-attributes

Allow to suppress '<' validation for attribute values
  • Loading branch information
FlorianRappl authored Jul 31, 2019
2 parents fdf519c + 21a44ed commit 4595c86
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/AngleSharp.Xml.Tests/Tokenizer/XmlTokenization.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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("<foo bar=\"a < b\">");

var t = CreateTokenizer(s);
t.IsSuppressingErrors = false;
Assert.Throws<XmlParseException>(() => t.Get());
}

[Test]
public void XmlTokenizerTagSuppressesWithADiamond()
{
var s = new TextSource("<foo bar=\"a < b\">");
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);
}
}
}
2 changes: 1 addition & 1 deletion src/AngleSharp.Xml/Parser/XmlTokenizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4595c86

Please sign in to comment.