Merge pull request #6588 from thundernest/keep_base_element

Keep `<base>` element
This commit is contained in:
cketti 2023-01-19 12:13:24 +01:00 committed by GitHub
commit 14c5c07e36
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 22 additions and 1 deletions

View file

@ -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) {

View file

@ -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() }
}