Skip to content

Should parse in Quirks Mode if doctype not set #2197

Closed

Description

@Muthukirthan

Input:

<html>
    <head></head>
    <body>
        <p>
            <span>
                <table>
                    <tbody>
                        <tr>
                            <td><span>Hello table data</span></td>
                        </tr>
                    </tbody>
                </table>
            </span>
        </p>
    </body>
</html>

Jsoup output:

<html>
    <head></head>
    <body>
        <p>
            <span>
                </span></p><table>
                    <tbody>
                        <tr>
                            <td><span>Hello table data</span></td>
                        </tr>
                    </tbody>
                </table>
            
        <p></p>
    </body>
</html>

Ref link: https://try.jsoup.org/~PNrKdofSo_QE8KX2IbZKZ-xxyq0

The table tag inside span of p tag is unwrapped as next sibling of p tag. Additionally an empty p tag is created as the next sibling of the unwrapped table tag. This output is not seen in Chrome and Firefox browsers

Activity

  1. jhy commented on Sep 10, 2024

    @jhy
    Owner

    Hi,

    The parse you are getting is coming from the implementation of this rule:

    A start tag whose tag name is "table".

    In HtmlTreeBuilderState, we are treating the document as No Quirks, but because there is no doctype, it should be treated as Quirks, and so the p should not be closed when the table gets opened.

    jsoup's doesn't currently implement Quirks Mode completely. We do go into quirks mode when parsing invalid doctypes, but don't have the expected doctype tests. Implementing that would allow this to be fixed.

    Checked in Chrome and if there is a valid doctype and so in No-Quirks mode, Chrome does parse the same as jsoup does currently:

    Screenshot 2024-09-10 at 3 19 26 PM
  2. changed the title [-]Jsoup Issue: <table> tag inside <span> of <p> tags are getting unwrapped outside and empty <p> tags are created[/-] [+]Should parse in Quirks Mode if doctype not set[/+] on Sep 10, 2024
  3. self-assigned this
    on Sep 10, 2024
  4. added
    fixedAn {bug|improvement} that has been {fixed|implemented}
    on Sep 10, 2024
  5. added this to the 1.18.2 milestone on Sep 10, 2024
  6. jhy commented on Sep 10, 2024

    @jhy
    Owner

    Thanks for reporting! Fixed.

  7. added a commit that references this issue on Sep 10, 2024
    8601e85
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

fixedAn {bug|improvement} that has been {fixed|implemented}

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions