Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Change minlength/maxlength behavior around linebreaks
As discussed in #1467, the current situation around these attributes is
not very interoperable. Some browsers count line breaks as two
characters (per the spec before this change), others as one character.

Per discussions, this updates minlength and maxlength to count line
breaks as one character. We believe this is the most developer-friendly
approach, as evidenced in part by repeated complaints against Chromium
for its behavior following the previous standard.

While here, updated the textLength property to return the code-point
length of the element's API value, instead of the element's value, since
as per http://software.hixie.ch/utilities/js/live-dom-viewer/?saved=4304
that is what browsers actually do. Similarly, updated the conformance
requirement on the text content of the textarea element to match
maxlength's actually-implemented behavior.

Fixes part of #1467, but the debate remains about code-unit length vs.
code-point length vs. number of grapheme clusters.
  • Loading branch information
domenic authored and annevk committed Aug 26, 2016
1 parent 4c228d3 commit 1637031
Showing 1 changed file with 58 additions and 43 deletions.
101 changes: 58 additions & 43 deletions source
Expand Up @@ -49557,28 +49557,30 @@ interface <dfn>HTMLTextAreaElement</dfn> : <span>HTMLElement</span> {

<p>For historical reasons, the element's value is normalised in three different ways for three
different purposes. The <span data-x="concept-textarea-raw-value">raw value</span> is the value as
it was originally set. It is not normalized. The <span data-x="concept-textarea-api-value">API
it was originally set. It is not normalised. The <span data-x="concept-fe-api-value">API
value</span> is the value used in the <code data-x="dom-textarea-value">value</code> IDL
attribute. It is normalised so that line breaks use U+000A LINE FEED (LF) characters. Finally,
there is the <span data-x="concept-fe-value">value</span>, as used in form submission and other
processing models in this specification. It is normalised so that line breaks use U+000D CARRIAGE
RETURN U+000A LINE FEED (CRLF) character pairs, and in addition, if necessary given the element's
<code data-x="attr-textarea-wrap">wrap</code> attribute, additional line breaks are inserted to
wrap the text at the given width.</p>
attribute, <code data-x="dom-textarea-textLength">textLength</code> IDL attribute, and by the
<code data-x="attr-fe-maxlength">maxlength</code> and <code
data-x="attr-fe-minlength">minlength</code> content attributes. It is normalised so that line
breaks use U+000A LINE FEED (LF) characters. Finally, there is the <span
data-x="concept-fe-value">value</span>, as used in form submission and other processing models in
this specification. It is normalised so that line breaks use U+000D CARRIAGE RETURN U+000A LINE
FEED (CRLF) character pairs, and in addition, if necessary given the element's <code
data-x="attr-textarea-wrap">wrap</code> attribute, additional line breaks are inserted to wrap the
text at the given width.</p>

<p>The element's <dfn data-x="concept-textarea-api-value">API value</dfn> is defined to be the
element's <span data-x="concept-textarea-raw-value">raw value</span> with the following
transformation applied:</p>
<p>The algorithm for obtaining the element's <span data-x="concept-fe-api-value">API value</span>
is to return the element's <span data-x="concept-textarea-raw-value">raw value</span> with the
<span>textarea line break normalisation transformation</span> applied. The <dfn>textarea line
break normalisation transformation</dfn> is the following algorithm, as applied to a string:</p>

<ol>

<li><p>Replace every U+000D CARRIAGE RETURN U+000A LINE FEED (CRLF) character pair from the <span
data-x="concept-textarea-raw-value">raw value</span> with a single U+000A LINE FEED (LF)
character.</p></li>
<li><p>Replace every U+000D CARRIAGE RETURN U+000A LINE FEED (CRLF) character pair with a single
U+000A LINE FEED (LF) character.</p></li>

<li><p>Replace every remaining U+000D CARRIAGE RETURN character from the <span
data-x="concept-textarea-raw-value">raw value</span> with a single U+000A LINE FEED (LF)
character.</p></li>
<li><p>Replace every remaining U+000D CARRIAGE RETURN character with a single U+000A LINE FEED
(LF) character.</p></li>

</ol>

Expand Down Expand Up @@ -49612,7 +49614,7 @@ interface <dfn>HTMLTextAreaElement</dfn> : <span>HTMLElement</span> {

<p>If the <code>textarea</code> element has a <span>maximum allowed value length</span>, then the
element's children must be such that the <span>code-unit length</span> of the value of the
element's <code>textContent</code> IDL attribute with the <span>textarea wrapping
element's <code>textContent</code> IDL attribute with the <span>textarea line break normalisation
transformation</span> applied is equal to or less than the element's <span>maximum allowed value
length</span>.</p>

Expand Down Expand Up @@ -49739,15 +49741,15 @@ interface <dfn>HTMLTextAreaElement</dfn> : <span>HTMLElement</span> {
act like the element's <code>textContent</code> IDL attribute.</p>

<p>The <dfn><code data-x="dom-textarea-value">value</code></dfn> IDL attribute must, on getting,
return the element's <span data-x="concept-textarea-api-value">API value</span>; on setting, it
must set the element's <span data-x="concept-textarea-raw-value">raw value</span> to the new
value, set the element's <span data-x="concept-textarea-dirty">dirty value flag</span> to true,
return the element's <span data-x="concept-fe-api-value">API value</span>; on setting, it must set
the element's <span data-x="concept-textarea-raw-value">raw value</span> to the new value, set the
element's <span data-x="concept-textarea-dirty">dirty value flag</span> to true,
and should then move the text entry cursor position to the end of the text control, unselecting
any selected text and resetting the selection direction to <i>none</i>.</p>

<p>The <dfn><code data-x="dom-textarea-textLength">textLength</code></dfn> IDL attribute must
return the <span>code-unit length</span> of the element's <span
data-x="concept-textarea-api-value">API value</span>.</p>
return the <span>code-unit length</span> of the element's <span data-x="concept-fe-api-value">API
value</span>.</p>

<p>The <code data-x="dom-cva-willValidate">willValidate</code>, <code
data-x="dom-cva-validity">validity</code>, and <code
Expand Down Expand Up @@ -51125,6 +51127,14 @@ interface <dfn>HTMLLegendElement</dfn> : <span>HTMLElement</span> {
element's <code data-x="attr-input-multiple">multiple</code> attribute, <code>input</code> elements
can also have separately defined <dfn data-x="concept-fe-values">value<em>s</em></dfn>.</p>

<p>To define the behavior of the <code data-x="attr-fe-maxlength">maxlength</code> and <code
data-x="attr-fe-minlength">minlength</code> attributes, as well as other APIs specific to the
<code>textarea</code> element, all form control with a <span
data-x="concept-fe-value">value</span> also have an algorithm for obtaining an <span
id="concept-textarea-api-value"></span><dfn data-x="concept-fe-api-value">API value</dfn>. By
default this algorithm is to simply return the control's <span
data-x="concept-fe-value">value</span>.</p>

<p>The <code>select</code> element does not have a <span data-x="concept-fe-value">value</span>;
the <span data-x="concept-option-selectedness">selectedness</span> of its <code>option</code>
elements is what is used instead.</p>
Expand Down Expand Up @@ -51371,7 +51381,9 @@ interface <dfn>HTMLLegendElement</dfn> : <span>HTMLElement</span> {

<p>A <dfn data-x="attr-fe-maxlength">form control <code data-x="">maxlength</code> attribute</dfn>,
controlled by a <var>dirty value flag</var>, declares a limit on the number of characters
a user can input.</p>
a user can input. The "number of characters" is measured using <span>code-unit length</span> and,
in the case of <code>textarea</code> elements, with all line breaks normalised to a single
character (as opposed to CRLF pairs).</p>

<p>If an element has its <span data-x="attr-fe-maxlength">form control <code
data-x="">maxlength</code> attribute</span> specified, the attribute's value must be a <span>valid
Expand All @@ -51386,17 +51398,18 @@ interface <dfn>HTMLLegendElement</dfn> : <span>HTMLElement</span> {
length</span>, its <var>dirty value flag</var> is true, its <span
data-x="concept-fe-value">value</span> was last changed by a user edit (as opposed to a change made
by a script), and the <span>code-unit length</span> of the element's <span
data-x="concept-fe-value">value</span> is greater than the element's <span>maximum allowed value
length</span>, then the element is <span>suffering from being too long</span>.</p>
data-x="concept-fe-api-value">API value</span> is greater than the element's <span>maximum allowed
value length</span>, then the element is <span>suffering from being too long</span>.</p>

<p>User agents may prevent the user from causing the element's <span
data-x="concept-fe-value">value</span> to be set to a value whose <span>code-unit length</span> is
greater than the element's <span>maximum allowed value length</span>.</p>
data-x="concept-fe-api-value">API value</span> to be set to a value whose <span>code-unit
length</span> is greater than the element's <span>maximum allowed value length</span>.</p>

<p class="note">In the case of <code>textarea</code> elements, this is the <span
data-x="concept-fe-value">value</span>, not the <span data-x="concept-textarea-raw-value">raw
value</span>, so the <span>textarea wrapping transformation</span> is applied before the
<span>maximum allowed value length</span> is checked.</p>
<p class="note">In the case of <code>textarea</code> elements, the <span
data-x="concept-fe-api-value">API value</span> and <span data-x="concept-fe-value">value</span>
differ. In particular, the <span>textarea line break normalisation transformation</span> is
applied before the <span>maximum allowed value length</span> is checked (whereas the
<span>textarea wrapping transformation</span> is not applied).</p>

</div>

Expand All @@ -51405,13 +51418,15 @@ interface <dfn>HTMLLegendElement</dfn> : <span>HTMLElement</span> {

<p>A <dfn data-x="attr-fe-minlength">form control <code data-x="">minlength</code> attribute</dfn>,
controlled by a <var>dirty value flag</var>, declares a lower bound on the number of
characters a user can input.</p>
characters a user can input. The "number of characters" is measured using <span>code-unit
length</span> and, in the case of <code>textarea</code> elements, with all line breaks normalised
to a single character (as opposed to CRLF pairs).</p>

<p class="note">The <code data-x="attr-fe-minlength">minlength</code> attribute does not imply the
<code data-x="">required</code> attribute. If the form control has no <code
data-x="">required</code> attribute, then the value can still be omitted; the
<code data-x="attr-fe-minlength">minlength</code> attribute only kicks in once the user has entered
a value at all. If the empty string is not allowed, then the <code data-x="">required</code>
data-x="">required</code> attribute, then the value can still be omitted; the <code
data-x="attr-fe-minlength">minlength</code> attribute only kicks in once the user has entered a
value at all. If the empty string is not allowed, then the <code data-x="">required</code>
attribute also needs to be set.</p>

<p>If an element has its <span data-x="attr-fe-minlength">form control <code
Expand All @@ -51429,11 +51444,11 @@ interface <dfn>HTMLLegendElement</dfn> : <span>HTMLElement</span> {

<p><strong>Constraint validation</strong>: If an element has a <span>minimum allowed value
length</span>, its <var>dirty value flag</var> is true, its <span
data-x="concept-fe-value">value</span> was last changed by a user edit (as opposed to a change made
by a script), its <span data-x="concept-fe-value">value</span> is not the empty string, and the
<span>code-unit length</span> of the element's <span data-x="concept-fe-value">value</span> is less
than the element's <span>minimum allowed value length</span>, then the element is <span>suffering
from being too short</span>.</p>
data-x="concept-fe-value">value</span> was last changed by a user edit (as opposed to a change
made by a script), its <span data-x="concept-fe-value">value</span> is not the empty string, and
the <span>code-unit length</span> of the element's <span data-x="concept-fe-api-value">API
value</span> is less than the element's <span>minimum allowed value length</span>, then the
element is <span>suffering from being too short</span>.</p>

</div>

Expand Down Expand Up @@ -55122,12 +55137,12 @@ fur
(CRLF) character pair.</p>

<p class="note">In the case of the <span data-x="concept-fe-value">value</span> of
<code>textarea</code> elements, this newline normalization is already performed during the
<code>textarea</code> elements, this newline normalisation is already performed during the
conversion of the control's <span data-x="concept-textarea-raw-value">raw value</span> into the
control's <span data-x="concept-fe-value">value</span> (which also performs any necessary line
wrapping). In the case of <code>input</code> elements <code data-x="attr-input-type">type</code>
attributes in the <span data-x="attr-input-type-file">File Upload</span> state, the value is not
normalized.</p>
normalised.</p>

</li>

Expand Down Expand Up @@ -60208,7 +60223,7 @@ idea from Mihai:
<dd>

<p>Returns a copy of the current line dash pattern. The array returned will always have an even
number of entries (i.e. the pattern is normalized).</p>
number of entries (i.e. the pattern is normalised).</p>

</dd>

Expand Down

0 comments on commit 1637031

Please sign in to comment.