Item 12 of 144 Previous | Next

1
Vote

HtmlEntity.Entitize > v1.4.0 failing on Chinese characters

description

If I execute these two assertions with 1.4.0, they both pass:

Assert.That(HtmlAgilityPack.HtmlEntity.DeEntitize("特别"), Is.EqualTo("特别"));

Assert.That(HtmlAgilityPack.HtmlEntity.Entitize("特别"), Is.EqualTo("特别"));

If I switch to 1.4.2 or 1.4.3, the first assertion passes, but the second fails on this exception:

System.Collections.Generic.KeyNotFoundException : The given key was not present in the dictionary.
at System.Collections.Generic.Dictionary`2.get_Item(TKey key)
at HtmlAgilityPack.HtmlEntity.Entitize(String text, Boolean useNames, Boolean entitizeQuotAmpAndLtGt) in HtmlEntity.cs: line 774
at HtmlAgilityPack.HtmlEntity.Entitize(String text) in HtmlEntity.cs: line 730

comments

kebet wrote Mar 15 at 8:39 PM

Modified line 774 to check for key in dictionary:

string entity = _entityName.ContainsKey(code)
? _entityName[code] as string
: null;

Attached updated HtmlEntity.cs and unit test.