Title: [177098] trunk
Revision
177098
Author
rn...@webkit.org
Date
2014-12-10 14:10:23 -0800 (Wed, 10 Dec 2014)

Log Message

REGRESSION(r164329): Input fields are not honoring the maxlength attribute
https://bugs.webkit.org/show_bug.cgi?id=139447

Reviewed by Benjamin Poulain.

Source/WebCore:

The bug was caused by String::substring being called with the selection's end offset
in the second argument instead of the selection's length in handleBeforeTextInsertedEvent.

Fixed the bug by passing the right second argument to String::substring.

Test: fast/forms/input-maxlength-inserting-in-middle.html

* html/TextFieldInputType.cpp:
(WebCore::TextFieldInputType::handleBeforeTextInsertedEvent):

LayoutTests:

Added regression tests.

* fast/forms/input-maxlength-inserting-in-middle-expected.txt: Added.
* fast/forms/input-maxlength-inserting-in-middle.html: Added.
* fast/forms/input-maxlength-paste-clusters-in-middle-expected.txt: Added.
* fast/forms/input-maxlength-paste-clusters-in-middle.html: Added.
* fast/forms/input-maxlength-paste-in-middle-expected.txt: Added.
* fast/forms/input-maxlength-paste-in-middle.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (177097 => 177098)


--- trunk/LayoutTests/ChangeLog	2014-12-10 21:51:20 UTC (rev 177097)
+++ trunk/LayoutTests/ChangeLog	2014-12-10 22:10:23 UTC (rev 177098)
@@ -1,3 +1,19 @@
+2014-12-10  Ryosuke Niwa  <rn...@webkit.org>
+
+        REGRESSION(r164329): Input fields are not honoring the maxlength attribute
+        https://bugs.webkit.org/show_bug.cgi?id=139447
+
+        Reviewed by Benjamin Poulain.
+
+        Added regression tests.
+
+        * fast/forms/input-maxlength-inserting-in-middle-expected.txt: Added.
+        * fast/forms/input-maxlength-inserting-in-middle.html: Added.
+        * fast/forms/input-maxlength-paste-clusters-in-middle-expected.txt: Added.
+        * fast/forms/input-maxlength-paste-clusters-in-middle.html: Added.
+        * fast/forms/input-maxlength-paste-in-middle-expected.txt: Added.
+        * fast/forms/input-maxlength-paste-in-middle.html: Added.
+
 2014-12-10  Antti Koivisto  <an...@apple.com>
 
         Crash when creating CSSCalcBinaryOperation

Added: trunk/LayoutTests/fast/forms/input-maxlength-inserting-in-middle-expected.txt (0 => 177098)


--- trunk/LayoutTests/fast/forms/input-maxlength-inserting-in-middle-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/input-maxlength-inserting-in-middle-expected.txt	2014-12-10 22:10:23 UTC (rev 177098)
@@ -0,0 +1,12 @@
+This test attempts to insert a character in the middle of a text field with maxlength.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS input.value is "abc"
+PASS input.getAttribute("maxlength") is "3"
+PASS input.value is "abc"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/forms/input-maxlength-inserting-in-middle.html (0 => 177098)


--- trunk/LayoutTests/fast/forms/input-maxlength-inserting-in-middle.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/input-maxlength-inserting-in-middle.html	2014-12-10 22:10:23 UTC (rev 177098)
@@ -0,0 +1,31 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<input type="text" maxlength="3" value="abc">
+<script>
+
+description('This test attempts to insert a character in the middle of a text field with maxlength.');
+
+var input = document.querySelector('input');
+input.focus();
+input.selectionStart = 1;
+input.selectionEnd = 1;
+shouldBeEqualToString('input.value', 'abc');
+shouldBeEqualToString('input.getAttribute("maxlength")', '3');
+
+input._oninput_ = function () {
+    shouldBeEqualToString('input.value', 'abc');
+}
+
+if (window.eventSender)
+    eventSender.keyDown('1');
+else
+    debug('To test manually, type in "1" into the text field. It should fail.');
+
+var successfullyParsed = true;
+
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/forms/input-maxlength-paste-clusters-in-middle-expected.txt (0 => 177098)


--- trunk/LayoutTests/fast/forms/input-maxlength-paste-clusters-in-middle-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/input-maxlength-paste-clusters-in-middle-expected.txt	2014-12-10 22:10:23 UTC (rev 177098)
@@ -0,0 +1,15 @@
+This test attempts to paste text in the middle of a text field with maxlength.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS input.value is "abc"
+PASS input.getAttribute("maxlength") is "3"
+input.selectionStart = input.selectionEnd = 2
+getSelection().modify("extend", "backward", "character")
+PASS document.execCommand("insertText", false, "स्"); input.value is "aस्c"
+PASS input.value.length is 4
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/forms/input-maxlength-paste-clusters-in-middle.html (0 => 177098)


--- trunk/LayoutTests/fast/forms/input-maxlength-paste-clusters-in-middle.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/input-maxlength-paste-clusters-in-middle.html	2014-12-10 22:10:23 UTC (rev 177098)
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<input type="text" maxlength="3" value="abc">
+<script>
+
+description('This test attempts to paste text in the middle of a text field with maxlength.');
+
+var input = document.querySelector('input');
+input.focus();
+input.selectionStart = 1;
+input.selectionEnd = 2;
+shouldBeEqualToString('input.value', 'abc');
+shouldBeEqualToString('input.getAttribute("maxlength")', '3');
+evalAndLog('input.selectionStart = input.selectionEnd = 2');
+evalAndLog('getSelection().modify("extend", "backward", "character")');
+shouldBeEqualToString('document.execCommand("insertText", false, "\u0938\u094D"); input.value', 'a\u0938\u094Dc');
+shouldBe('input.value.length', '4');
+
+var successfullyParsed = true;
+
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/forms/input-maxlength-paste-in-middle-expected.txt (0 => 177098)


--- trunk/LayoutTests/fast/forms/input-maxlength-paste-in-middle-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/input-maxlength-paste-in-middle-expected.txt	2014-12-10 22:10:23 UTC (rev 177098)
@@ -0,0 +1,14 @@
+This test attempts to paste text in the middle of a text field with maxlength.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS input.value is "abc"
+PASS input.getAttribute("maxlength") is "3"
+input.selectionStart = 1
+input.selectionEnd = 2
+PASS document.execCommand("insertText", false, "123"); input.value is "a1c"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/forms/input-maxlength-paste-in-middle.html (0 => 177098)


--- trunk/LayoutTests/fast/forms/input-maxlength-paste-in-middle.html	                        (rev 0)
+++ trunk/LayoutTests/fast/forms/input-maxlength-paste-in-middle.html	2014-12-10 22:10:23 UTC (rev 177098)
@@ -0,0 +1,23 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<input type="text" maxlength="3" value="abc">
+<script>
+
+description('This test attempts to paste text in the middle of a text field with maxlength.');
+
+var input = document.querySelector('input');
+input.focus();
+shouldBeEqualToString('input.value', 'abc');
+shouldBeEqualToString('input.getAttribute("maxlength")', '3');
+evalAndLog('input.selectionStart = 1');
+evalAndLog('input.selectionEnd = 2');
+shouldBeEqualToString('document.execCommand("insertText", false, "123"); input.value', 'a1c');
+
+var successfullyParsed = true;
+
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (177097 => 177098)


--- trunk/Source/WebCore/ChangeLog	2014-12-10 21:51:20 UTC (rev 177097)
+++ trunk/Source/WebCore/ChangeLog	2014-12-10 22:10:23 UTC (rev 177098)
@@ -1,3 +1,20 @@
+2014-12-10  Ryosuke Niwa  <rn...@webkit.org>
+
+        REGRESSION(r164329): Input fields are not honoring the maxlength attribute
+        https://bugs.webkit.org/show_bug.cgi?id=139447
+
+        Reviewed by Benjamin Poulain.
+
+        The bug was caused by String::substring being called with the selection's end offset
+        in the second argument instead of the selection's length in handleBeforeTextInsertedEvent.
+
+        Fixed the bug by passing the right second argument to String::substring.
+
+        Test: fast/forms/input-maxlength-inserting-in-middle.html
+
+        * html/TextFieldInputType.cpp:
+        (WebCore::TextFieldInputType::handleBeforeTextInsertedEvent):
+
 2014-12-10  Anders Carlsson  <ander...@apple.com>
 
         Add a missing null check.

Modified: trunk/Source/WebCore/html/TextFieldInputType.cpp (177097 => 177098)


--- trunk/Source/WebCore/html/TextFieldInputType.cpp	2014-12-10 21:51:20 UTC (rev 177097)
+++ trunk/Source/WebCore/html/TextFieldInputType.cpp	2014-12-10 22:10:23 UTC (rev 177098)
@@ -384,7 +384,10 @@
     unsigned selectionLength = 0;
     if (element().focused()) {
         ASSERT(enclosingTextFormControl(element().document().frame()->selection().selection().start()) == &element());
-        selectionLength = numGraphemeClusters(innerText.substring(element().selectionStart(), element().selectionEnd()));
+        int selectionStart = element().selectionStart();
+        ASSERT(selectionStart <= element().selectionEnd());
+        int selectionCodeUnitCount = element().selectionEnd() - selectionStart;
+        selectionLength = selectionCodeUnitCount ? numGraphemeClusters(innerText.substring(selectionStart, selectionCodeUnitCount)) : 0;
     }
     ASSERT(oldLength >= selectionLength);
 
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to