Re: Self closing tag error message

Chuck Houpt (chuck@habilis.net) kirjoitti:

>
> > On Sep 29, 2022, at 2:41 PM, Jukka K. Korpela <jukkakk@gmail.com> wrote:
> >
> > Is there a rationale for this? The “self-closing” syntax like <br/>
> looks perfectly harmless to me. Of course, it’s a holdover from the era
> when “XHTML” was popular without any good reason, but in non-XML parsing
> <br/> has always been read as <br>.
>
> The main rationale seems to be that self-closing syntax interacts badly
> with optional attribute quoting. For example, the following causes
> confusion:
>
> <link rel=stylesheet href=/styles.css/>
>

Indeed.


>
> Through XML-colored glasses, it may looks like it should load
> "/styles.css", but browsers will try to load "/styles.css/" and get a 404.
>

It is not well-formed XML, due to the lack of attribute quoting, so a truly
XML user agent does not process the document at all after detecting this.

Existing browsers indeed interpret it so that the attribute value is
"/styles.css/". But if you insert a space before the second slash, the
space terminates attribute parsing and all goes well in practice. The
second slash is ignored. And for a long time, it was recommended to make
your HTML documents “XHTML ready” by using “/” in empty element tags but
putting a space before the slash for compatibility with existing user
agents. This was rather pointless, of course.

In terms of HTML defined as an SGML application, it is still an error,
since the attribute value needs to be quoted due to the “/” at the start of
it. But consider this:
<link rel=stylesheet href=styles.css />
The attribute value is now valid by SGML rules, and so is the element as a
whole. Yet, what we get from the validator, when validating against HTML
4.01, is two incompatible error messages:
NET-enabling start-tag requires SHORTTAG YES
character data is not allowed here
The first one is wrong, as an error message, since the declaration for HTML
4.01 clearly sets SHORTTAG YES:
https://www.w3.org/TR/html401/sgml/sgmldecl.html
The second one is the result of actually parsing the construct by SGML
rules under that declaration, i,.e. the “/” terminates the tag and the
element, and the subsequent “>” then becomes character data inside the head
element, surely not allowed there.


> I think that self-closing tags have always been an error in HTML. The
> error was flagged by the HTML 2-4 validators, so this change just brings
> the HTML 5+ validator back in line.
>

No, “self-closing tags” were always valid in HTML as an SGML application.
But HTML was never actually implemented as an SGML application. Not in a
single browser. So it is rather misleading to “validate” documents against
such specifications.

In practical terms, <br /> or even <br/> was and is harmless in text/html;
it is simply treated as <br>,

The current problem is that when validating against “living HTML”,
triggered with <!doctype html>, without specifying an XML document type,
even the modest
<br />
triggers the verbose warning
Warning: Self-closing tag syntax in text/html documents is widely
discouraged
<https://google.github.io/styleguide/htmlcssguide.html#Document_Type>; it’s
unnecessary and interacts badly with other HTML features
<https://software.hixie.ch/utilities/js/live-dom-viewer/?saved=10809> (e.g.,
unquoted attribute values). If you’re using a tool that injects
self-closing tag syntax into all void elements, without any option to
prevent it from doing so <https://github.com/prettier/prettier/issues/5246>,
then consider switching to a different tool.
Getting this a dozen or more times is annoying, and this seems to be
intentional (trying to make software vendors to change their code or users
to switch to other software or to waste time in deleting slashes).

This is disproportional. The link “interactus badly...” refers to a cryptic
page, and it seems to be all about unquoted attribute values used together
with s “/” without a preceding space, so this is the issue that should be
targeted, not the legacy or cargo-cult use of “self-closing tag syntax” as
such (a misnomer, by the way; it’s about a tag closing the element, not the
tag itself).

Jukka, https://jkorpela.fi

Received on Wednesday, 5 October 2022 19:50:57 UTC