-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Change minlength/maxlength behavior around linebreaks #1712
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
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. Fixes part of #1467, but the debate remains about code-unit length vs. code-point length vs. number of grapheme clusters.
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -49631,28 +49631,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 linebreak normalisation transformation</span> applied. The <dfn>textarea linebreak | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 24 hits for "line break" in HTML, 0 for "linebreak" |
||
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> | ||
|
||
|
@@ -49686,7 +49688,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 linebreak normalisation | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The commit message says nothing about the wrapping transformation not being relevant here. Are you sure that should be removed? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a conformance requirement that mismatched the actual check that maxlength does. Let me add a bit to the commit message. |
||
transformation</span> applied is equal to or less than the element's <span>maximum allowed value | ||
length</span>.</p> | ||
|
||
|
@@ -49813,15 +49815,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 | ||
|
@@ -51199,6 +51201,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> | ||
|
@@ -51445,7 +51455,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 linebreaks 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 | ||
|
@@ -51460,17 +51472,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 linebreak 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> | ||
|
||
|
@@ -51479,7 +51492,9 @@ 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 linebreaks 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 | ||
|
@@ -51503,11 +51518,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> | ||
|
||
|
@@ -55196,12 +55211,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> | ||
|
||
|
@@ -60282,7 +60297,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> | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would we apply this to all form elements and not just
textarea
elements?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, I guess this is defined in the
textarea
element section and therefore onlytextarea
overrides the default.