input[maxlength=0] should ignore text input.

https://bugs.webkit.org/show_bug.cgi?id=65497

Patch by Shinya Kawanaka <shinyak@google.com> on 2011-08-19
Reviewed by Kent Tamura.

Source/WebCore:

Changed the valid range of maxlength.

* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::parseMaxLengthAttribute):
  Changed maxlength check condition.

LayoutTests:

* fast/forms/input-text-paste-maxlength-expected.txt:
  Added a case that maxlength=0
* fast/forms/input-text-paste-maxlength.html: ditto.
* fast/forms/script-tests/textarea-maxlength.js: ditto.
(createFocusedTextAreaWithMaxLength):
* fast/forms/textarea-maxlength-expected.txt: ditto.

git-svn-id: svn://svn.chromium.org/blink/trunk@93390 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent 3f1e785c
2011-08-19 Shinya Kawanaka <shinyak@google.com>
input[maxlength=0] should ignore text input.
https://bugs.webkit.org/show_bug.cgi?id=65497
Reviewed by Kent Tamura.
* fast/forms/input-text-paste-maxlength-expected.txt:
Added a case that maxlength=0
* fast/forms/input-text-paste-maxlength.html: ditto.
* fast/forms/script-tests/textarea-maxlength.js: ditto.
(createFocusedTextAreaWithMaxLength):
* fast/forms/textarea-maxlength-expected.txt: ditto.
2011-08-19 Ilya Tikhonovsky <loislo@chromium.org> 2011-08-19 Ilya Tikhonovsky <loislo@chromium.org>
Web Inspector: backend js api: an ability to skip optional arguments in the middle of the argument list is required. Web Inspector: backend js api: an ability to skip optional arguments in the middle of the argument list is required.
...@@ -25,7 +25,10 @@ PASS visibleValueOf('g') is '12' + fancyX + '45' ...@@ -25,7 +25,10 @@ PASS visibleValueOf('g') is '12' + fancyX + '45'
pasting too much text pasting too much text
PASS domValueOf('k') is '12' + fancyX + '4' PASS domValueOf('k') is '12' + fancyX + '4'
PASS visibleValueOf('k') is '12' + fancyX + '4' PASS visibleValueOf('k') is '12' + fancyX + '4'
pasting too much text with maxlength=0
PASS domValueOf('l') is ''
PASS visibleValueOf('l') is ''
PASS successfullyParsed is true PASS successfullyParsed is true
TEST COMPLETE TEST COMPLETE
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
<input type="text" id="h" size="5"> <input type="text" id="h" size="5">
<input type="text" id="g" size="5"> <input type="text" id="g" size="5">
<input type="text" id="k" size="5" maxlength="4"> <input type="text" id="k" size="5" maxlength="4">
<input type="text" id="l" size="5" maxlength="0">
<script> <script>
function domValueOf(id) { function domValueOf(id) {
...@@ -93,6 +94,12 @@ document.execCommand("InsertHTML", false, "12x&#x305;&#x332;45"); ...@@ -93,6 +94,12 @@ document.execCommand("InsertHTML", false, "12x&#x305;&#x332;45");
shouldBe("domValueOf('k')", "'12' + fancyX + '4'"); shouldBe("domValueOf('k')", "'12' + fancyX + '4'");
shouldBe("visibleValueOf('k')", "'12' + fancyX + '4'"); shouldBe("visibleValueOf('k')", "'12' + fancyX + '4'");
debug("pasting too much text with maxlength=0");
document.getElementById("l").focus();
document.execCommand("InsertHTML", false, "12x&#x305;&#x332;45");
shouldBe("domValueOf('l')", "''");
shouldBe("visibleValueOf('l')", "''");
var successfullyParsed = true; var successfullyParsed = true;
</script> </script>
<script src="../../fast/js/resources/js-test-post.js"></script> <script src="../../fast/js/resources/js-test-post.js"></script>
......
...@@ -42,60 +42,60 @@ textArea.value = 'abcde'; ...@@ -42,60 +42,60 @@ textArea.value = 'abcde';
shouldBe('textArea.value', '"abcde"'); shouldBe('textArea.value', '"abcde"');
// Set up for user-input tests // Set up for user-input tests
function createFocusedTextAreaWithMaxLength3() { function createFocusedTextAreaWithMaxLength(maxLength) {
if (textArea) if (textArea)
document.body.removeChild(textArea); document.body.removeChild(textArea);
textArea = document.createElement('textarea'); textArea = document.createElement('textarea');
textArea.setAttribute('maxlength', '3'); textArea.setAttribute('maxlength', maxLength);
document.body.appendChild(textArea); document.body.appendChild(textArea);
textArea.focus(); textArea.focus();
} }
// Insert text of which length is maxLength. // Insert text of which length is maxLength.
createFocusedTextAreaWithMaxLength3(); createFocusedTextAreaWithMaxLength(3);
document.execCommand('insertText', false, 'abc'); document.execCommand('insertText', false, 'abc');
shouldBe('textArea.value', '"abc"'); shouldBe('textArea.value', '"abc"');
// Try to add characters to maxLength characters. // Try to add characters to maxLength characters.
createFocusedTextAreaWithMaxLength3(); createFocusedTextAreaWithMaxLength(3);
textArea.value = 'abc'; textArea.value = 'abc';
document.execCommand('insertText', false, 'def'); document.execCommand('insertText', false, 'def');
shouldBe('textArea.value', '"abc"'); shouldBe('textArea.value', '"abc"');
// Replace text // Replace text
createFocusedTextAreaWithMaxLength3(); createFocusedTextAreaWithMaxLength(3);
textArea.value = 'abc'; textArea.value = 'abc';
document.execCommand('selectAll'); document.execCommand('selectAll');
document.execCommand('insertText', false, 'def'); document.execCommand('insertText', false, 'def');
shouldBe('textArea.value', '"def"'); shouldBe('textArea.value', '"def"');
// Existing value is longer than maxLength. We can't add text. // Existing value is longer than maxLength. We can't add text.
createFocusedTextAreaWithMaxLength3(); createFocusedTextAreaWithMaxLength(3);
textArea.value = 'abcdef'; textArea.value = 'abcdef';
document.execCommand('insertText', false, 'ghi'); document.execCommand('insertText', false, 'ghi');
shouldBe('textArea.value', '"abcdef"'); shouldBe('textArea.value', '"abcdef"');
// We can delete a character in the longer value. // We can delete a character in the longer value.
createFocusedTextAreaWithMaxLength3(); createFocusedTextAreaWithMaxLength(3);
textArea.value = 'abcdef'; textArea.value = 'abcdef';
document.execCommand('delete'); document.execCommand('delete');
shouldBe('textArea.value', '"abcde"'); shouldBe('textArea.value', '"abcde"');
// A linebreak is 1 character. // A linebreak is 1 character.
createFocusedTextAreaWithMaxLength3(); createFocusedTextAreaWithMaxLength(3);
document.execCommand('insertText', false, 'A'); document.execCommand('insertText', false, 'A');
document.execCommand('insertLineBreak'); document.execCommand('insertLineBreak');
document.execCommand('insertText', false, 'B'); document.execCommand('insertText', false, 'B');
shouldBe('textArea.value', '"A\\nB"'); shouldBe('textArea.value', '"A\\nB"');
// Confirms correct count for close linebreaks inputs. // Confirms correct count for close linebreaks inputs.
createFocusedTextAreaWithMaxLength3(); createFocusedTextAreaWithMaxLength(3);
textArea.innerHTML = 'a\n\n'; textArea.innerHTML = 'a\n\n';
document.execCommand('insertLineBreak'); document.execCommand('insertLineBreak');
shouldBe('textArea.value', '"a\\n\\n"'); shouldBe('textArea.value', '"a\\n\\n"');
// Confirms correct count for open consecutive linebreaks inputs. // Confirms correct count for open consecutive linebreaks inputs.
createFocusedTextAreaWithMaxLength3(); createFocusedTextAreaWithMaxLength(3);
document.execCommand('insertLineBreak'); document.execCommand('insertLineBreak');
document.execCommand('insertLineBreak'); document.execCommand('insertLineBreak');
document.execCommand('insertLineBreak'); document.execCommand('insertLineBreak');
...@@ -111,27 +111,33 @@ var fancyX = "x\u0305\u0332";// + String.fromCharCode(0x305) + String.fromCharCo ...@@ -111,27 +111,33 @@ var fancyX = "x\u0305\u0332";// + String.fromCharCode(0x305) + String.fromCharCo
var u10000 = "\ud800\udc00"; var u10000 = "\ud800\udc00";
// Inserts 5 code-points in UTF-16 // Inserts 5 code-points in UTF-16
createFocusedTextAreaWithMaxLength3(); createFocusedTextAreaWithMaxLength(3);
document.execCommand('insertText', false, 'AB' + fancyX); document.execCommand('insertText', false, 'AB' + fancyX);
shouldBe('textArea.value', '"AB" + fancyX'); shouldBe('textArea.value', '"AB" + fancyX');
shouldBe('textArea.value.length', '5'); shouldBe('textArea.value.length', '5');
createFocusedTextAreaWithMaxLength3(); createFocusedTextAreaWithMaxLength(3);
textArea.value = 'AB' + fancyX; textArea.value = 'AB' + fancyX;
textArea.setSelectionRange(2, 5); // Select fancyX textArea.setSelectionRange(2, 5); // Select fancyX
document.execCommand('insertText', false, 'CDE'); document.execCommand('insertText', false, 'CDE');
shouldBe('textArea.value', '"ABC"'); shouldBe('textArea.value', '"ABC"');
// Inserts 4 code-points in UTF-16 // Inserts 4 code-points in UTF-16
createFocusedTextAreaWithMaxLength3(); createFocusedTextAreaWithMaxLength(3);
document.execCommand('insertText', false, 'AB' + u10000); document.execCommand('insertText', false, 'AB' + u10000);
shouldBe('textArea.value', '"AB" + u10000'); shouldBe('textArea.value', '"AB" + u10000');
shouldBe('textArea.value.length', '4'); shouldBe('textArea.value.length', '4');
createFocusedTextAreaWithMaxLength3(); createFocusedTextAreaWithMaxLength(3);
textArea.value = 'AB' + u10000; textArea.value = 'AB' + u10000;
textArea.setSelectionRange(2, 4); // Select u10000 textArea.setSelectionRange(2, 4); // Select u10000
document.execCommand('insertText', false, 'CDE'); document.execCommand('insertText', false, 'CDE');
shouldBe('textArea.value', '"ABC"'); shouldBe('textArea.value', '"ABC"');
// In the case maxlength=0
createFocusedTextAreaWithMaxLength(0);
textArea.value = '';
document.execCommand('insertText', false, 'ABC');
shouldBe('textArea.value', '""');
var successfullyParsed = true; var successfullyParsed = true;
...@@ -29,6 +29,7 @@ PASS textArea.value is "ABC" ...@@ -29,6 +29,7 @@ PASS textArea.value is "ABC"
PASS textArea.value is "AB" + u10000 PASS textArea.value is "AB" + u10000
PASS textArea.value.length is 4 PASS textArea.value.length is 4
PASS textArea.value is "ABC" PASS textArea.value is "ABC"
PASS textArea.value is ""
PASS successfullyParsed is true PASS successfullyParsed is true
TEST COMPLETE TEST COMPLETE
......
2011-08-19 Shinya Kawanaka <shinyak@google.com>
input[maxlength=0] should ignore text input.
https://bugs.webkit.org/show_bug.cgi?id=65497
Reviewed by Kent Tamura.
Changed the valid range of maxlength.
* html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::parseMaxLengthAttribute):
Changed maxlength check condition.
2011-08-19 Ilya Tikhonovsky <loislo@chromium.org> 2011-08-19 Ilya Tikhonovsky <loislo@chromium.org>
Web Inspector: backend js api: an ability to skip optional arguments in the middle of the argument list is required. Web Inspector: backend js api: an ability to skip optional arguments in the middle of the argument list is required.
...@@ -1922,7 +1922,7 @@ void HTMLInputElement::notifyFormStateChanged() ...@@ -1922,7 +1922,7 @@ void HTMLInputElement::notifyFormStateChanged()
void HTMLInputElement::parseMaxLengthAttribute(Attribute* attribute) void HTMLInputElement::parseMaxLengthAttribute(Attribute* attribute)
{ {
int maxLength = attribute->isNull() ? maximumLength : attribute->value().toInt(); int maxLength = attribute->isNull() ? maximumLength : attribute->value().toInt();
if (maxLength <= 0 || maxLength > maximumLength) if (maxLength < 0 || maxLength > maximumLength)
maxLength = maximumLength; maxLength = maximumLength;
int oldMaxLength = m_maxLength; int oldMaxLength = m_maxLength;
m_maxLength = maxLength; m_maxLength = maxLength;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment