All contributions

zzzprojects/html-agility-pack

Html Agility Pack

An HTML parser for .NET written in C#, which builds a read/write DOM and supports XPath and XSLT, including for HTML taken straight from the web.

Language
C#
GitHub stars
2,850
Merged changes
1
Project site
html-agility-pack.net

What we changed

HtmlEntity.DeEntitize leaves invalid numeric entities such as &#foo; and &#xGG; unchanged instead of adding a second # to them.

What this work shows

  • HTML character references
  • Fallback paths in exception handling
  • Parameterised xUnit tests
What was broken

An invalid entity got a second #

HtmlEntity.DeEntitize turned &#foo; into &##foo; and &#xGG; into &##xGG;. When the number could not be parsed, the catch block prepended &# to a value that already started with #, so the function damaged text it was meant to leave alone.

How we fixed it

The original text restored exactly

The catch block now prepends only &, the same way the named-entity branch already did. An xUnit test covers invalid entities, also inside surrounding text, and checks that A, A and & still decode.

#611

Merged change 1

  1. #611 Fix HtmlEntity.DeEntitize duplicating '#' on invalid numeric entities Merged 12 October 2026

What it taught us

A fallback meant to restore the original text has to rebuild it character for character. If it adds something the variable already holds, the function silently damages text it was meant to leave alone.

More about this technology: C# and .NET

Other projects we write code for

Describe your project.

A free quote comes back within an hour during working hours.