Skip to content

Printer is over eager to remove white space in 1.20.1 #2325

@Mahoney

Description

@Mahoney

Given this HTML fragment:

<span>in span</span>
Text after span

parsing in 1.20.1 removes all of the whitespace between the end of the span tag and Text after span, leaving this:

<span>in span</span>Text after span

It should leave in at least one white space to be the same HTML:

<span>in span</span> Text after span

Failing test:

package foo;

import static org.jsoup.Jsoup.parse;

public class Jsoup {

    public static void main(String[] args) {
        var parsed = parse(
            """
            <html>
             <head></head>
             <body>
              <span>in span</span>
              Text after span
             </body>
            </html>
            """, "");
        var expected =
           """
           <html>
            <head></head>
            <body>
             <span>in span</span> Text after span
            </body>
           </html>
           """;
        if (!parsed.toString().equals(expected)) {
            throw new AssertionError("["+parsed+"] should be ["+expected+"]");
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA confirmed bug, that we should fixfixedAn {bug|improvement} that has been {fixed|implemented}

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions