---
title: "Html Agility Pack: invalid HTML entities in C# | VulCode"
description: "A fix to Html Agility Pack, the .NET HTML parser in C#: DeEntitize leaves invalid numeric entities unchanged instead of inserting a second # into them."
url: "https://vulcode.com/en/opensource/contributions/html-agility-pack"
lang: "en"
---

[All contributions](https://vulcode.com/en/opensource/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.

[See the repository](https://github.com/zzzprojects/html-agility-pack) [All contributions](https://vulcode.com/en/opensource/contributions)

- **Language**: C#
- **GitHub stars**: 2,850
- **Merged changes**: 1
- **Project site**: [html-agility-pack.net](https://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 &#65;, &#x41; and &amp; still decode.

[#611](https://github.com/zzzprojects/html-agility-pack/pull/611)

## Merged change 1

- [#611 Fix HtmlEntity.DeEntitize duplicating '#' on invalid numeric entities Merged 12 October 2026](https://github.com/zzzprojects/html-agility-pack/pull/611)

## 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](https://vulcode.com/en/technologies/csharp-and-dotnet)

## Other projects we write code for

- [**ILSpy** C# · 27,138 stars An open source .NET decompiler that turns compiled assemblies back into readable C# code. It is used to inspect libraries whose source code is not at hand.](https://vulcode.com/en/opensource/contributions/ilspy)

- [**OpenRA** C# · 17,827 stars An open source real-time strategy engine for classic Westwood games such as Command & Conquer: Red Alert, written in C# with SDL and OpenGL.](https://vulcode.com/en/opensource/contributions/openra)

- [**Polly** C# · 14,255 stars A .NET library for handling transient faults: retries, circuit breakers, timeouts and fallback. Its Simmy module injects faults on purpose to test how an application copes with them.](https://vulcode.com/en/opensource/contributions/polly)

- [**FluentValidation** C# · 9,780 stars A popular .NET library for writing strongly typed validation rules in a fluent style, such as RuleFor(...).InclusiveBetween(...).](https://vulcode.com/en/opensource/contributions/fluentvalidation)

- [**Serilog** C# · 8,064 stars A structured logging library for .NET. It records events from message templates, with named properties rather than plain text.](https://vulcode.com/en/opensource/contributions/serilog)

- [**NLog** C# · 6,547 stars A flexible structured logging library for many .NET platforms, configured through layouts, filters and targets.](https://vulcode.com/en/opensource/contributions/nlog)

## Describe your project.

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

### Rather skip the form?

Ask in the chat or write to us directly.

Open the chat

- **Email**: [hello@vulcode.com](mailto:hello@vulcode.com)
- **Phone**: [+48 576 043 920](tel:+48576043920)
- **Discord**: [discord.gg/vulcode](https://discord.gg/vulcode)
