> Constraint validation: If an element has a maximum allowed value length, its dirty value flag is true, its value was last changed by a user edit (as opposed to a change made by a script), and the length of the element's API value is greater than the element's maximum allowed value length, then the element is suffering from being too long.
Where "the length of" is a link to [2]:
> A string’s length is the number of code units it contains.
And "code units" is a link to [3]:
> A string is a sequence of unsigned 16-bit integers, also known as code units.
I agree with your implied point that this is a questionable definition, though!
[1] https://html.spec.whatwg.org/multipage/form-control-infrastr...
“User agents _may_ prevent the user from causing the element's API value to be set to a value whose length is greater than the element's maximum allowed value length.”
and we have “MAY This word, or the adjective "OPTIONAL", mean that an item is truly optional” [2]
[1] https://html.spec.whatwg.org/multipage/form-control-infrastr...
I do not rule out that, if you look at the source code or git history of their code, there are comments or test cases explicitly stating they deviate from enforcing a fixed maximum length in code points if doing so breaks up a grapheme cluster.
Also: what do other browsers do when you paste, for example, an ‘é’ that is made up of two code points ‘e’ and a combining character into a field that accepts only a single further code point? Do they just add an ‘e’?
Choosing 16-bit code points as the base keeps consistency with the naive string length counting algorithm of JS, in particular, which has always returned length in 16-bit code points.
Sure, it's slightly to the detriment of user experience in terms of how a user expects graphemes to be counted, but it avoids later storage problems.
Consistency with JavaScript does make some sense at least.
Obviously there are a lot of databases out there with hacks using things like bad UTF-8 in unsafe column formats not designed for it, of course. But if you are working with a database like that, codepoint counting is possibly among your least worries.
The length in code units is unambiguous and constant across versions.