Re: [EXT] Legal characters in id name

Frank da Cruz wrote:
https://html.spec.whatwg.org/multipage/dom.html#the-id-attribute (Last Updated 26 February 2021) says:

"The id attribute specifies its element's unique identifier (ID). There are no other restrictions on what form an ID can take; in particular, IDs can consist of just digits, start with a digit, start with an underscore, consist of just punctuation, etc.  An element's unique identifier can be used for a variety of purposes, most notably as a way to link to specific parts of a document using fragments, as a way to target an element when scripting, and as a way to style a specific element from CSS."

The HTML5 validator accepts id="[-123-]" but not href="#[-123-]":

"Bad value #[-13-] for attribute href on element a: Illegal character in fragment: [ is not allowed."

But clicking on the link works.

Many things work, Frank.  However, the validator is not defined in terms of what works (in a particular browser, under a particular operating system, when the moon is in a particular house, and so on) but rather in terms of what is stated in the corresponding specification.  Note in particular :

The href attribute on a<https://www.w3.org/TR/html52/single-page.html#elementdef-a> and area<https://www.w3.org/TR/html52/single-page.html#elementdef-area> elements must have a value that is a valid URL potentially surrounded by spaces<https://www.w3.org/TR/html52/single-page.html#valid-url-potentially-surrounded-by-spaces>.

A quick look at the value you are ascribing to your HREF indicates that you are trying to include square brackets.  The specification<http://www.ietf.org/rfc/rfc3986.txt> says :

A host identified by an Internet Protocol literal address, version 6 [RFC3513] or later, is distinguished by enclosing the IP literal within square brackets ("[" and "]"). This is the only place where square bracket characters are allowed in the URI syntax.

Therefore, in order to be compliant, you will need to URL-encode your square brackets.
--
Philip Taylor



This email, its contents and any attachments are intended solely for the addressee and may contain confidential information. In certain circumstances, it may also be subject to legal privilege. Any unauthorised use, disclosure, or copying is not permitted. If you have received this email in error, please notify us and immediately and permanently delete it. Any views or opinions expressed in personal emails are solely those of the author and do not necessarily represent those of Royal Holloway, University of London. It is your responsibility to ensure that this email and any attachments are virus free.

Received on Saturday, 27 February 2021 15:23:26 UTC