Skip to content

Commit

Permalink
Remove nesting of bodies when sanitizing html
Browse files Browse the repository at this point in the history
  • Loading branch information
LunarX committed Jul 5, 2024
1 parent a326815 commit 7f56baa
Showing 1 changed file with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,14 @@ internal class BodyCleaner {

fun clean(dirtyDocument: Document): Document {
val cleanedDocument = cleaner.clean(dirtyDocument)

// Cleaner.clean() nests two bodies inside one-another. To fix this, unwrap one of them so we don't end up with nested bodies
val body = cleanedDocument.body()
val hasNestedBodies = body.childNodeSize() == 1
&& body.childrenSize() == 1
&& body.children()[0].tagName().lowercase() == "body"
if (hasNestedBodies) body.unwrap()

copyDocumentType(dirtyDocument, cleanedDocument)
return cleanedDocument
}
Expand Down

0 comments on commit 7f56baa

Please sign in to comment.