@Test
public void preserveDoubleEscapingInAttributes() throws Exception
{

    CleanerProperties cleanerProperties = new CleanerProperties();
    cleanerProperties.setDeserializeEntities(true);
    HtmlCleaner cleaner = new HtmlCleaner(cleanerProperties);
    TagNode tagNode = cleaner.clean("<?xml version = \"1.0\"?><div foo=\"&amp;quot;\">&amp;quot;</div>");
    List<? extends TagNode> divList = tagNode.getElementListByName("div", true);
    assertEquals(1, divList.size());
    assertEquals("&quot;", divList.get(0).getText().toString());
    // This assert is failing: the attribute is deserialized to contain ".
    assertEquals("&quot;", divList.get(0).getAttributeByName("foo"));
    DomSerializer domSerializer = new DomSerializer(cleanerProperties, false);
    Document document = domSerializer.createDOM(tagNode);
    NodeList nodeList = document.getElementsByTagName("div");
    assertEquals(1, nodeList.getLength());
    assertEquals("&quot;", nodeList.item(0).getTextContent());
    assertEquals("&quot;", nodeList.item(0).getAttributes().getNamedItem("foo").getTextContent());
    document = this.cleaner.clean(new StringReader("<div foo=\"&amp;quot;\">&amp;quot;</div>"));
    nodeList = document.getElementsByTagName("div");
    assertEquals(1, nodeList.getLength());
    assertEquals("&quot;", nodeList.item(0).getTextContent());
    // We can never retrieve the expected value here since the encoded &amp; has been lost earlier.
    assertEquals("&quot;", nodeList.item(0).getAttributes().getNamedItem("foo").getTextContent());
    assertHTML("<div foo=\"&amp;quot;\">content</div>",
        "<div foo=\"&amp;quot;\">content</div>");
}