Title: [103051] trunk
Revision
103051
Author
commit-qu...@webkit.org
Date
2011-12-16 02:48:05 -0800 (Fri, 16 Dec 2011)

Log Message

[Forms] The "maxlength" attribute on "textarea" tag miscounts hard newlines
https://bugs.webkit.org/show_bug.cgi?id=74686

Patch by Yosifumi Inoue <yo...@chromium.org> on 2011-12-16
Reviewed by Kent Tamura.

Source/WebCore:

This patch counts LF in textarea value as two for LF to CRLF conversion on submission.

No new tests. Existing tests cover all changes.

* html/HTMLTextAreaElement.cpp:
(WebCore::computeLengthForSubmission): Count LF as 2 for CR LF conversion on submission.
(WebCore::HTMLTextAreaElement::handleBeforeTextInsertedEvent): Use computeLengthForSubmission instead of numGraphemeClusters.
(WebCore::HTMLTextAreaElement::tooLong): Use computeLengthForSubmission instead of numGraphemeClusters.

LayoutTests:

* fast/forms/script-tests/textarea-maxlength.js: Doubles maxlength for counting LF as two chars.

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (103050 => 103051)


--- trunk/LayoutTests/ChangeLog	2011-12-16 10:44:04 UTC (rev 103050)
+++ trunk/LayoutTests/ChangeLog	2011-12-16 10:48:05 UTC (rev 103051)
@@ -1,3 +1,12 @@
+2011-12-16  Yosifumi Inoue  <yo...@chromium.org>
+
+        [Forms] The "maxlength" attribute on "textarea" tag miscounts hard newlines
+        https://bugs.webkit.org/show_bug.cgi?id=74686
+
+        Reviewed by Kent Tamura.
+
+        * fast/forms/script-tests/textarea-maxlength.js: Doubles maxlength for counting LF as two chars.
+
 2011-12-16  Hajime Morrita  <morr...@chromium.org>
 
         Unreviewed, rolling out r103045.

Modified: trunk/LayoutTests/fast/forms/script-tests/textarea-maxlength.js (103050 => 103051)


--- trunk/LayoutTests/fast/forms/script-tests/textarea-maxlength.js	2011-12-16 10:44:04 UTC (rev 103050)
+++ trunk/LayoutTests/fast/forms/script-tests/textarea-maxlength.js	2011-12-16 10:48:05 UTC (rev 103051)
@@ -82,7 +82,7 @@
 shouldBe('textArea.value', '"abcde"');
 
 // A linebreak is 1 character.
-createFocusedTextAreaWithMaxLength(3);
+createFocusedTextAreaWithMaxLength(4);
 document.execCommand('insertText', false, 'A');
 document.execCommand('insertLineBreak');
 document.execCommand('insertText', false, 'B');
@@ -95,7 +95,7 @@
 shouldBe('textArea.value', '"a\\n\\n"');
 
 // Confirms correct count for open consecutive linebreaks inputs.
-createFocusedTextAreaWithMaxLength(3);
+createFocusedTextAreaWithMaxLength(6);
 document.execCommand('insertLineBreak');
 document.execCommand('insertLineBreak');
 document.execCommand('insertLineBreak');

Modified: trunk/Source/WebCore/ChangeLog (103050 => 103051)


--- trunk/Source/WebCore/ChangeLog	2011-12-16 10:44:04 UTC (rev 103050)
+++ trunk/Source/WebCore/ChangeLog	2011-12-16 10:48:05 UTC (rev 103051)
@@ -1,3 +1,19 @@
+2011-12-16  Yosifumi Inoue  <yo...@chromium.org>
+
+        [Forms] The "maxlength" attribute on "textarea" tag miscounts hard newlines
+        https://bugs.webkit.org/show_bug.cgi?id=74686
+
+        Reviewed by Kent Tamura.
+
+        This patch counts LF in textarea value as two for LF to CRLF conversion on submission.
+
+        No new tests. Existing tests cover all changes.
+
+        * html/HTMLTextAreaElement.cpp:
+        (WebCore::computeLengthForSubmission): Count LF as 2 for CR LF conversion on submission.
+        (WebCore::HTMLTextAreaElement::handleBeforeTextInsertedEvent): Use computeLengthForSubmission instead of numGraphemeClusters.
+        (WebCore::HTMLTextAreaElement::tooLong): Use computeLengthForSubmission instead of numGraphemeClusters.
+
 2011-12-16  Hajime Morrita  <morr...@chromium.org>
 
         Unreviewed, rolling out r103045.

Modified: trunk/Source/WebCore/html/HTMLTextAreaElement.cpp (103050 => 103051)


--- trunk/Source/WebCore/html/HTMLTextAreaElement.cpp	2011-12-16 10:44:04 UTC (rev 103050)
+++ trunk/Source/WebCore/html/HTMLTextAreaElement.cpp	2011-12-16 10:48:05 UTC (rev 103051)
@@ -50,6 +50,19 @@
 static const int defaultRows = 2;
 static const int defaultCols = 20;
 
+// On submission, LF characters are converted into CRLF.
+// This function returns number of characters considering this.
+static unsigned computeLengthForSubmission(const String& text)
+{
+    unsigned count =  numGraphemeClusters(text);
+    unsigned length = text.length();
+    for (unsigned i = 0; i < length; i++) {
+        if (text[i] == '\n')
+            count++;
+    }
+    return count;
+}
+
 HTMLTextAreaElement::HTMLTextAreaElement(const QualifiedName& tagName, Document* document, HTMLFormElement* form)
     : HTMLTextFormControlElement(tagName, document, form)
     , m_rows(defaultRows)
@@ -244,13 +257,13 @@
         return;
     unsigned unsignedMaxLength = static_cast<unsigned>(signedMaxLength);
 
-    unsigned currentLength = numGraphemeClusters(innerTextValue());
+    unsigned currentLength = computeLengthForSubmission(innerTextValue());
     // selectionLength represents the selection length of this text field to be
     // removed by this insertion.
     // If the text field has no focus, we don't need to take account of the
     // selection length. The selection is the source of text drag-and-drop in
     // that case, and nothing in the text field will be removed.
-    unsigned selectionLength = focused() ? numGraphemeClusters(plainText(document()->frame()->selection()->selection().toNormalizedRange().get())) : 0;
+    unsigned selectionLength = focused() ? computeLengthForSubmission(plainText(document()->frame()->selection()->selection().toNormalizedRange().get())) : 0;
     ASSERT(currentLength >= selectionLength);
     unsigned baseLength = currentLength - selectionLength;
     unsigned appendableLength = unsignedMaxLength > baseLength ? unsignedMaxLength - baseLength : 0;
@@ -402,7 +415,7 @@
     int max = maxLength();
     if (max < 0)
         return false;
-    return numGraphemeClusters(value) > static_cast<unsigned>(max);
+    return computeLengthForSubmission(value) > static_cast<unsigned>(max);
 }
 
 bool HTMLTextAreaElement::isValidValue(const String& candidate) const
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to