wawandco / milo

Milo is an HTML linter written in Go
MIT License
20 stars 0 forks source link

False Positive 0015:tag/pair on auto-closed <iframe/> #42

Closed christianhujer closed 4 years ago

christianhujer commented 4 years ago

Given the following well-formed and valid XHTML 5.2 file

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <title>Milo Test</title>
</head>
<body>
    <h1>Milo Test</h1>
    <p>
        This XHTML auto-closing <iframe src="src" width="40" height="30" />.
    </p>
</body>
</html>

Milo wrongly reports

false-positives/pair.xhtml:2:1: tag-pair: Tag must be paired (0015:tag/pair)
false-positives/pair.xhtml:6:1: tag-pair: Tag must be paired (0015:tag/pair)
false-positives/pair.xhtml:8:1: tag-pair: Tag must be paired (0015:tag/pair)
christianhujer commented 4 years ago

This also happens on auto-closed <script/>.

paganotoni commented 4 years ago

Hey @christianhujer 👋. Thanks for reporting this one. Unfortunately none of these 2 tags are intended to be self-closing, even tho most of the browsers will understand it I think that’s syntactically incorrect.

paganotoni commented 4 years ago

To be clear I’m not 100% sure about this but the list of void elements in the HTML5 spec does not include in frame or script. Do you have a reference that states that iframes and scripts are void ?

https://html.spec.whatwg.org/multipage/syntax.html#void-elements

christianhujer commented 4 years ago

What you are missing is that "not self-closing" relates to the HTML syntax of HTML documents. The HTML specification allows for two syntaxes of HTML documents, the HTML syntax and the XML Syntax (usually referred to as XHTML). As I clearly stated in the bug report, this is an XHTML file, which is HTML using the XML syntax. The element isn't self-closing, the tag denoting the element is the XML EmptyElementTag syntax, it is closed explicitly by the /> at its end. (The typical file suffix, as seen from the error message, is .xhtml, and the Internet Media Type (fka MIME TYpe) is application/xhtml+xml.)

For more information:

And from the chapter that you've referred to:

This section only describes the rules for resources labeled with an HTML MIME type. Rules for XML resources are discussed in the section below entitled "The XML syntax".

paganotoni commented 4 years ago

Yes. You're right on this one. To start we're focusing on the HTML syntax for HTML. Maybe later we can work on the XML syntax.