When a numeric character reference (&#...;) fails to parse, the catch block restored the text as "&#" + e where e already begins with '#', producing a doubled '#' (for example "&#foo;" became "&##foo;"). Restore the original text as "&" + e + ";" to match the named-entity fallback and keep DeEntitize idempotent for unparseable numeric entities.
26 lines
883 B
C#
26 lines
883 B
C#
using Xunit;
|
|
|
|
namespace HtmlAgilityPack.Tests.NetStandard2_0
|
|
{
|
|
public class HtmlEntityDeEntitizeTests
|
|
{
|
|
[Theory]
|
|
// Invalid numeric entities must be left untouched; "&#foo;" used to become
|
|
// "&##foo;".
|
|
[InlineData("&#foo;", "&#foo;")]
|
|
[InlineData("&#xGG;", "&#xGG;")]
|
|
[InlineData("&#;", "&#;")]
|
|
[InlineData("prefix &#foo; suffix", "prefix &#foo; suffix")]
|
|
// Valid numeric entities keep decoding correctly.
|
|
[InlineData("A", "A")]
|
|
[InlineData("A", "A")]
|
|
// Named entities are unaffected.
|
|
[InlineData("&", "&")]
|
|
[InlineData("¬real;", "¬real;")]
|
|
public void DeEntitize_HandlesInvalidNumericEntitiesWithoutDuplicatingHash(string input, string expected)
|
|
{
|
|
Assert.Equal(expected, HtmlEntity.DeEntitize(input));
|
|
}
|
|
}
|
|
}
|