Merge pull request #6588 from thundernest/keep_base_element
Keep `<base>` element
This commit is contained in:
commit
14c5c07e36
2 changed files with 22 additions and 1 deletions
|
@ -9,7 +9,7 @@ import org.jsoup.parser.Tag
|
|||
import org.jsoup.select.NodeTraversor
|
||||
import org.jsoup.select.NodeVisitor
|
||||
|
||||
private val ALLOWED_TAGS = listOf("style", "meta")
|
||||
private val ALLOWED_TAGS = listOf("style", "meta", "base")
|
||||
|
||||
internal class HeadCleaner {
|
||||
fun clean(dirtyDocument: Document, cleanedDocument: Document) {
|
||||
|
|
|
@ -465,6 +465,25 @@ class HtmlSanitizerTest {
|
|||
assertTagsNotStripped("var")
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `should keep 'base' element`() {
|
||||
val html =
|
||||
"""
|
||||
<html>
|
||||
<head>
|
||||
<base href="https://domain.example/">
|
||||
</head>
|
||||
<body>
|
||||
<a href="relative">Link</a>
|
||||
</body>
|
||||
</html>
|
||||
""".compactHtml()
|
||||
|
||||
val result = htmlSanitizer.sanitize(html)
|
||||
|
||||
assertThat(result.toCompactString()).isEqualTo(html)
|
||||
}
|
||||
|
||||
private fun assertTagsNotStripped(element: String) {
|
||||
val html = """<$element>some text</$element>"""
|
||||
|
||||
|
@ -491,4 +510,6 @@ class HtmlSanitizerTest {
|
|||
}
|
||||
|
||||
private fun String.trimLineBreaks() = replace("\n", "")
|
||||
|
||||
private fun String.compactHtml() = lines().joinToString(separator = "") { it.trim() }
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue