Skip to content

HtmlUnit 2.57.0 asNormalizedText() is incorrect when isCSSEnabled is false #439

Description

@jeffcjohnson

In 2.57.0, asNormalizedText() is missing linefeeds on some block layout tags if CSS is disabled, even when no CSS is present in the HTML.

============= webClient.options.isCssEnabled = true =============
p 
br
p
p 
br 
br 
br
p
============= webClient.options.isCssEnabled = false =============
p 
br p p 
br 
br 
br p
import com.gargoylesoftware.htmlunit.WebClient
import com.gargoylesoftware.htmlunit.html.HtmlPage

fun testAsNormalizedTextWithCssDisabled() {
    val content = """
        <div>
            <p>p
                <br>br
            </p>
            <p>p</p>
            <p>p
                <br>br
                <br>br
                <br>br
            </p>
            <p>p</p>
        </div>
    """.trimIndent()

    val webClient = WebClient()

    webClient.loadHtmlCodeIntoCurrentWindow(content)
    val page = webClient.currentWindow.enclosedPage as HtmlPage

    println("============= webClient.options.isCssEnabled = true =============")
    webClient.options.isCssEnabled = true  // default is true
    println(page.asNormalizedText())

    println("============= webClient.options.isCssEnabled = false =============")
    webClient.options.isCssEnabled = false
    println(page.asNormalizedText())
}

fun main() {
    testAsNormalizedTextWithCssDisabled()
}

PS: thanks for HtmlUnit, it is awesome!

Activity

rbri commented on Feb 1, 2022

@rbri
Member

PS: thanks for HtmlUnit, it is awesome!

Your are welcome (and github stars also ;-)

I think i found the root cause of the problem - will make a new snapshot build available is the CI is happy with the fix.
Please check on twitter for any updates.

rbri commented on Feb 1, 2022

@rbri
Member

CI is happy - new snapshot is available.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions