Skip to content

Problem with template inside button #2271

Closed

Description

@felixscheinost

Probably related to #2258.

Parsing the following HTML even with master (checked out 5d31cac at the moment), doesn't work:

<button>
  <template>
    <button></button>
  </template>
</button>

I think that HTML should be valid according to spec. MDN says that template is allowed inside every element that accepts phrasing content and buttons accept phrasing content.

I also put that snippet through https://validator.w3.org which passed:

Image

Still it doesn't get parsed correctly. I added a test to HtmlParserTest. The test currently passes that way, which is incorrect:

    @Test void templateInButton() {
        String html = "<button> <template><button></button></template> </button>";
        Document doc = Jsoup.parse(html);
        assertEquals("<button><template></template></button><button></button>",
                TextUtil.stripNewlines(doc.body().html()));
    }

We can see that the inner button ends up being interpreted as a sibling of the outer button.

Activity

  1. added
    fixedAn {bug|improvement} that has been {fixed|implemented}
    on Feb 24, 2025
  2. added this to the 1.19.1 milestone on Feb 24, 2025
  3. jhy commented on Feb 24, 2025

    @jhy
    Owner

    Thanks, fixed!

  4. added a commit that references this issue on Feb 24, 2025
    b875b92
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