Skip to content

Instantly share code, notes, and snippets.

Created January 22, 2013 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/4597820 to your computer and use it in GitHub Desktop.
Save anonymous/4597820 to your computer and use it in GitHub Desktop.
Hippo HtmlRepairer v1.02.06 Div only allows for class attribute
} else if (startElement.localName.equals(ELEM_DIV)) {
String classAttr = startElement.attrs.getValue(ATTR_CLASS);
Set<String> allowedDivClasses = template.getAllowedDivClasses();
if (classAttr != null && allowedDivClasses.contains(classAttr)) {
AttributesImpl attrs = new AttributesImpl();
attrs.addAttribute(EMPTY_STRING, ATTR_CLASS, ATTR_CLASS, CDATA, classAttr);
startElement(ELEM_DIV, attrs);
endElements.push(new EndElementInfo(ELEM_DIV));
} else {
// unallowed class, drop div element
endElements.push(new EndElementInfo());
}
} else if (startElement.localName.equals(ELEM_P)) {
String classAttr = startElement.attrs.getValue(ATTR_CLASS);
Set<String> allowedParaClasses = template.getAllowedParaClasses();
if (classAttr != null && allowedParaClasses.contains(classAttr)) {
startElement(ELEM_P, getAllowedAttributes(startElement));
endElements.push(new EndElementInfo(ELEM_P));
} else {
AttributesImpl attrs = getAllowedAttributes(startElement);
int classPos = attrs.getIndex(ATTR_CLASS);
if (classPos != -1) {
attrs.removeAttribute(classPos);
}
startElement(ELEM_P, attrs);
endElements.push(new EndElementInfo(ELEM_P));
}
}
@jpboudreault
Copy link

As we see, div only keep the class attribute vs p which allows the ones configured

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment