@Test
public void sanitizationBypassPreservedAcrossClone() throws Exception {
String markup = "<p foo=\"bar\"><b>Parag</b><!--raph--></p>";
// Create a rewriter that would strip everything
GadgetRewriter rewriter = createRewriter(set(), set());
MutableContent mc = new MutableContent(parser, markup);
Document document = mc.getDocument();
Element paragraphTag = (Element) document.getElementsByTagName("p").item(0);
// Mark the paragraph tag element as trusted
SanitizingGadgetRewriter.bypassSanitization(paragraphTag, false);
// Now, clone the paragraph tag and replace the paragraph tag
Element cloned = (Element) paragraphTag.cloneNode(true);
paragraphTag.getParentNode().replaceChild(cloned, paragraphTag);
rewriter.rewrite(gadget, mc);
// The document should be unchanged
String content = mc.getContent();
Matcher matcher = BODY_REGEX.matcher(content);
matcher.matches();