Skip to content

Problem with template inside button #2271

@felixscheinost

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.

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