Skip to content

Improper Html closing tag results in addition of text nodes #2230

Closed

Description

@Muthukirthan

Jsoup is not able determine improperly closed html tags.
For example,
<a> hello </a< would result in <a> hello </a>&lt;
<div> hello </div<> would result in <div> hello </div>&lt;&gt;

Browsers will properly close the tags and does not add a &lt; or &gt; text nodes like Jsoup

Activity

  1. jhy commented on Nov 23, 2024

    @jhy
    Owner

    See #797 - at that point we moved out of spec. But the spec used to add the < character as an attribute name, not to the tag name. https://html.spec.whatwg.org/multipage/parsing.html#tag-name-state

    Will review moving closer to spec and impact.

  2. jhy commented on Nov 23, 2024

    @jhy
    Owner

    OK, I've aligned it to the current spec. That allows tag names like a<b (and you can see that in Chrome with HTML like <div> hello </div<> <a>One<a<b>Hello</b>). That's pretty gross IMO, but better for us to be consistent.

  3. added
    fixedAn {bug|improvement} that has been {fixed|implemented}
    on Nov 23, 2024
  4. added this to the 1.18.2 milestone on Nov 23, 2024
  5. added a commit that references this issue on Nov 23, 2024
    0ef4b70
  6. jochenberger commented on Nov 29, 2024

    @jochenberger

    This change just pointed me to some invalid HTML that I was generating, so thanks! 🙂

    I was generating (more or less) the following:

    <table><th</></th></table>

    1.18.1 turned that into

    <html>
     <head></head>
     <body>
      <table>
       <tbody>
        <tr>
         <th></th>
        </tr>
       </tbody>
      </table>
     </body>
    </html>

    Now, with 1.18.2, it get

    <html>
     <head></head>
     <body>
      <th< />
      <table></table>
     </body>
    </html>

    I assume that it's related to this change. I just wanted to make sure that the new behavior is expected.

  7. jhy commented on Dec 3, 2024

    @jhy
    Owner

    Thanks @jochenberger -- yes that is what we would expect now. The previous #797 behavior was probably a better experience for this case, but ultimately lead to too much difference betwen browsers/spec and jsoup.

    The th< tag is getting promoted ahead of the table tag in your instance due to the table parsing rules that move non-table elements out of the table.

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

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

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions