Fix Bug 14388: Input in text fields limited to 1024 characters
authoraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Jul 2007 01:58:37 +0000 (01:58 +0000)
committeraroben <aroben@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 6 Jul 2007 01:58:37 +0000 (01:58 +0000)
WebCore:

2007-07-05  Alp Toker  <alp.toker@collabora.co.uk>

        Fix Bug 14388: Input in text fields limited to 1024 characters
        http://bugs.webkit.org/show_bug.cgi?id=14388

        Slightly modified by Adam Roben.

        Reviewed by Adele.

        Test: fast/forms/input-length.html

        * html/HTMLInputElement.cpp: Bump limit to 524288.
        (WebCore::HTMLInputElement::init):
        (WebCore::HTMLInputElement::parseMappedAttribute):
        * html/HTMLInputElement.h:

LayoutTests:

        Added two tests for Bug 14388: Input in text fields limited to 1024 characters

        fast/forms/input-maxlength-2.html is obsoleted by
        fast/forms/input-maxlength.html.

        Reviewed by Adele.

        * fast/forms/input-implicit-length-limit-expected.txt: Added.
        * fast/forms/input-implicit-length-limit.html: Added.
        * fast/forms/input-maxlength-2-expected.checksum: Removed.
        * fast/forms/input-maxlength-2-expected.png: Removed.
        * fast/forms/input-maxlength-2-expected.txt: Removed.
        * fast/forms/input-maxlength-2.html: Removed.
        * fast/forms/input-maxlength-expected.txt: Added.
        * fast/forms/input-maxlength.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@24037 268f45cc-cd09-0410-ab3c-d52691b4dbfc

12 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/forms/input-implicit-length-limit-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/input-implicit-length-limit.html [new file with mode: 0644]
LayoutTests/fast/forms/input-maxlength-2-expected.checksum [deleted file]
LayoutTests/fast/forms/input-maxlength-2-expected.png [deleted file]
LayoutTests/fast/forms/input-maxlength-2-expected.txt [deleted file]
LayoutTests/fast/forms/input-maxlength-2.html [deleted file]
LayoutTests/fast/forms/input-maxlength-expected.txt [new file with mode: 0644]
LayoutTests/fast/forms/input-maxlength.html [new file with mode: 0644]
WebCore/ChangeLog
WebCore/html/HTMLInputElement.cpp
WebCore/html/HTMLInputElement.h

index 5a1dd66480bbc5821bbd4512f7b3153684c5393a..c6aa07cd2992e4d61e001c761a7834f5fbcedf38 100644 (file)
         * mac/leopard/fast/encoding/idn-security-expected.txt: Copied from fast/encoding/idn-security-expected.txt.
         The modified.
 
+2007-07-05  Adam Roben  <aroben@apple.com>
+
+        Added two tests for Bug 14388: Input in text fields limited to 1024 characters
+
+        fast/forms/input-maxlength-2.html is obsoleted by
+        fast/forms/input-maxlength.html.
+
+        Reviewed by Adele.
+
+        * fast/forms/input-implicit-length-limit-expected.txt: Added.
+        * fast/forms/input-implicit-length-limit.html: Added.
+        * fast/forms/input-maxlength-2-expected.checksum: Removed.
+        * fast/forms/input-maxlength-2-expected.png: Removed.
+        * fast/forms/input-maxlength-2-expected.txt: Removed.
+        * fast/forms/input-maxlength-2.html: Removed.
+        * fast/forms/input-maxlength-expected.txt: Added.
+        * fast/forms/input-maxlength.html: Added.
+
 2007-07-05  Adam Roben  <aroben@apple.com>
 
         Add another hanging test to the Leopard Skipped file
diff --git a/LayoutTests/fast/forms/input-implicit-length-limit-expected.txt b/LayoutTests/fast/forms/input-implicit-length-limit-expected.txt
new file mode 100644 (file)
index 0000000..e645dd1
--- /dev/null
@@ -0,0 +1,18 @@
+This page tests that the length of an <input> element's string is implicitly limited to 524288 characters. http://bugs.webkit.org/show_bug.cgi?id=14388
+
+
+Attempting to insert 0 characters.
+PASS
+Attempting to insert 5 characters.
+PASS
+Attempting to insert 1025 characters.
+PASS
+Attempting to insert 524287 characters.
+PASS
+Attempting to insert 524288 characters.
+PASS
+Attempting to insert 524289 characters.
+PASS
+Attempting to insert 530000 characters.
+PASS
+
diff --git a/LayoutTests/fast/forms/input-implicit-length-limit.html b/LayoutTests/fast/forms/input-implicit-length-limit.html
new file mode 100644 (file)
index 0000000..4470761
--- /dev/null
@@ -0,0 +1,41 @@
+<p>This page tests that the length of an <tt>&lt;input&gt;</tt> element's string is implicitly limited to 524288 characters. <a href="http://bugs.webkit.org/show_bug.cgi?id=14388">http://bugs.webkit.org/show_bug.cgi?id=14388</a></p>
+<input id="input">
+<pre id="log"></pre>
+<script>
+    function log(msg)
+    {
+        document.getElementById("log").appendChild(document.createTextNode(msg + "\n"));
+    }
+
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+
+    var testString = "";
+
+    function attempt(length, expected)
+    {
+        log("Attempting to insert " + length + " characters.");
+
+        if (testString.length > length)
+            testString = "";
+
+        for (var i = testString.length; i < length; ++i)
+            testString += i % 10;
+
+        var input = document.getElementById("input");
+        input.value = testString;
+
+        if (input.value.length == expected)
+            log("PASS");
+        else
+            log("FAIL: Expected " + expected + " characters to be inserted, but " + input.value.length + " characters were actually inserted.");
+    }
+
+    attempt(0, 0);
+    attempt(5, 5);
+    attempt(1025, 1025);
+    attempt(524287, 524287);
+    attempt(524288, 524288);
+    attempt(524289, 524288);
+    attempt(530000, 524288);
+</script>
diff --git a/LayoutTests/fast/forms/input-maxlength-2-expected.checksum b/LayoutTests/fast/forms/input-maxlength-2-expected.checksum
deleted file mode 100644 (file)
index 2471a35..0000000
+++ /dev/null
@@ -1 +0,0 @@
-63a7e999da3bc216eeb50e6c15abe12a
\ No newline at end of file
diff --git a/LayoutTests/fast/forms/input-maxlength-2-expected.png b/LayoutTests/fast/forms/input-maxlength-2-expected.png
deleted file mode 100644 (file)
index df90a7c..0000000
Binary files a/LayoutTests/fast/forms/input-maxlength-2-expected.png and /dev/null differ
diff --git a/LayoutTests/fast/forms/input-maxlength-2-expected.txt b/LayoutTests/fast/forms/input-maxlength-2-expected.txt
deleted file mode 100644 (file)
index 7d678f0..0000000
+++ /dev/null
@@ -1,16 +0,0 @@
-layer at (0,0) size 800x600
-  RenderView at (0,0) size 800x600
-layer at (0,0) size 800x600
-  RenderBlock {HTML} at (0,0) size 800x600
-    RenderBody {BODY} at (8,8) size 784x584
-      RenderBlock {P} at (0,0) size 784x18
-        RenderText {#text} at (0,0) size 540x18
-          text run at (0,0) width 540: "The string pasted into the text field should be truncated at the maxlength, 5 characters."
-      RenderBlock (anonymous) at (0,34) size 784x23
-        RenderTextControl {INPUT} at (2,2) size 148x19 [bgcolor=#FFFFFF] [border: (2px inset #000000)]
-        RenderText {#text} at (0,0) size 0x0
-layer at (13,47) size 142x13
-  RenderBlock {DIV} at (3,3) size 142x13
-    RenderText {#text} at (1,0) size 35x13
-      text run at (1,0) width 35: "12345"
-caret: position 5 of child 0 {#text} of child 0 {DIV} of child 2 {INPUT} of child 0 {BODY} of child 0 {HTML} of document
diff --git a/LayoutTests/fast/forms/input-maxlength-2.html b/LayoutTests/fast/forms/input-maxlength-2.html
deleted file mode 100644 (file)
index bab8d87..0000000
+++ /dev/null
@@ -1,9 +0,0 @@
-<p>The string pasted into the text field should be truncated at the maxlength, 5 characters.</p>
-<input maxlength="5" id="test" type="text">
-
-<script>
-var e = document.getElementById("test");
-e.focus();
-e.setSelectionRange(0, 0);
-document.execCommand("InsertHTML", false, "123456789");
-</script>
\ No newline at end of file
diff --git a/LayoutTests/fast/forms/input-maxlength-expected.txt b/LayoutTests/fast/forms/input-maxlength-expected.txt
new file mode 100644 (file)
index 0000000..d0744f4
--- /dev/null
@@ -0,0 +1,76 @@
+This page tests that the maxlength attribute of the <input> element works correctly. http://bugs.webkit.org/show_bug.cgi?id=14388
+
+
+Attempting to insert 0 characters with maxLength = -1.
+PASS
+Attempting to insert 0 characters with maxLength = 100.
+PASS
+Attempting to insert 0 characters with maxLength = 524288.
+PASS
+Attempting to insert 0 characters with maxLength = 600000.
+PASS
+Attempting to insert 5 characters with maxLength = -1.
+PASS
+Attempting to insert 5 characters with maxLength = 100.
+PASS
+Attempting to insert 5 characters with maxLength = 524288.
+PASS
+Attempting to insert 5 characters with maxLength = 600000.
+PASS
+Attempting to insert 100 characters with maxLength = -1.
+PASS
+Attempting to insert 100 characters with maxLength = 100.
+PASS
+Attempting to insert 100 characters with maxLength = 524288.
+PASS
+Attempting to insert 100 characters with maxLength = 600000.
+PASS
+Attempting to insert 101 characters with maxLength = -1.
+PASS
+Attempting to insert 101 characters with maxLength = 100.
+PASS
+Attempting to insert 101 characters with maxLength = 524288.
+PASS
+Attempting to insert 101 characters with maxLength = 600000.
+PASS
+Attempting to insert 200 characters with maxLength = -1.
+PASS
+Attempting to insert 200 characters with maxLength = 100.
+PASS
+Attempting to insert 200 characters with maxLength = 524288.
+PASS
+Attempting to insert 200 characters with maxLength = 600000.
+PASS
+Attempting to insert 524287 characters with maxLength = -1.
+PASS
+Attempting to insert 524287 characters with maxLength = 100.
+PASS
+Attempting to insert 524287 characters with maxLength = 524288.
+PASS
+Attempting to insert 524287 characters with maxLength = 600000.
+PASS
+Attempting to insert 524288 characters with maxLength = -1.
+PASS
+Attempting to insert 524288 characters with maxLength = 100.
+PASS
+Attempting to insert 524288 characters with maxLength = 524288.
+PASS
+Attempting to insert 524288 characters with maxLength = 600000.
+PASS
+Attempting to insert 524289 characters with maxLength = -1.
+PASS
+Attempting to insert 524289 characters with maxLength = 100.
+PASS
+Attempting to insert 524289 characters with maxLength = 524288.
+PASS
+Attempting to insert 524289 characters with maxLength = 600000.
+PASS
+Attempting to insert 530000 characters with maxLength = -1.
+PASS
+Attempting to insert 530000 characters with maxLength = 100.
+PASS
+Attempting to insert 530000 characters with maxLength = 524288.
+PASS
+Attempting to insert 530000 characters with maxLength = 600000.
+PASS
+
diff --git a/LayoutTests/fast/forms/input-maxlength.html b/LayoutTests/fast/forms/input-maxlength.html
new file mode 100644 (file)
index 0000000..efb90e3
--- /dev/null
@@ -0,0 +1,50 @@
+<p>This page tests that the <tt>maxlength</tt> attribute of the <tt>&lt;input&gt;</tt> element works correctly. <a href="http://bugs.webkit.org/show_bug.cgi?id=14388">http://bugs.webkit.org/show_bug.cgi?id=14388</a></p>
+<input id="input">
+<pre id="log"></pre>
+<script>
+    function log(msg)
+    {
+        document.getElementById("log").appendChild(document.createTextNode(msg + "\n"));
+    }
+
+    if (window.layoutTestController)
+        layoutTestController.dumpAsText();
+
+    var testString = "";
+    var input = document.getElementById("input");
+
+    function attempt(length, expected)
+    {
+        log("Attempting to insert " + length + " characters with maxLength = " + input.getAttribute("maxlength") + ".");
+
+        if (testString.length > length)
+            testString = "";
+
+        for (var i = testString.length; i < length; ++i)
+            testString += i % 10;
+
+        input.value = testString;
+
+        if (input.value.length == expected)
+            log("PASS");
+        else
+            log("FAIL: Expected " + expected + " characters to be inserted, but " + input.value.length + " characters were actually inserted.");
+    }
+
+    var implicitMaxLength = 524288;
+
+    var stringLengthsToTest = [0, 5, 100, 101, 200, 524287, 524288, 524289, 530000];
+    var maxLengthsToTest = ["-1", "100", "524288", "600000"];
+
+    for (var i = 0; i < stringLengthsToTest.length; ++i) {
+        var stringLength = stringLengthsToTest[i];
+        for (var j = 0; j < maxLengthsToTest.length; ++j) {
+            var maxLength = maxLengthsToTest[j];
+            input.setAttribute("maxlength", maxLength);
+            if (maxLength < 0 || maxLength > implicitMaxLength)
+                maxLength = implicitMaxLength;
+            var expected = Math.min(stringLength, maxLength);
+            attempt(stringLength, expected);
+        }
+    }
+</script>
index 5a28bce3fe80a245c3fc3cdda3be4767e500d029..dcd103e059553fdcd5370b37c747855aafcc7e06 100644 (file)
@@ -1,3 +1,20 @@
+2007-07-05  Alp Toker  <alp.toker@collabora.co.uk>
+
+        Fix Bug 14388: Input in text fields limited to 1024 characters
+        http://bugs.webkit.org/show_bug.cgi?id=14388
+
+        Slightly modified by Adam Roben.
+
+        Reviewed by Adele.
+
+        Tests: fast/forms/input-implicit-length-limit.html
+               fast/forms/input-maxlength.html
+
+        * html/HTMLInputElement.cpp: Bump limit to 524288.
+        (WebCore::HTMLInputElement::init):
+        (WebCore::HTMLInputElement::parseMappedAttribute):
+        * html/HTMLInputElement.h:
+
 2007-07-05  Anders Carlsson  <andersca@apple.com>
 
         Build fix.
index ff202770c89d15c1d839368b37a03fecbfc5c2ea..7b8c4ac5583035a815fbd36e3efd83ea48c0be09 100644 (file)
@@ -63,6 +63,12 @@ using namespace HTMLNames;
 
 const int maxSavedResults = 256;
 
+// FIXME: According to HTML4, the length attribute's value can be arbitrarily
+// large. However, due to http://bugs.webkit.org/show_bugs.cgi?id=14536 things
+// get rather sluggish when a text field has a larger number of characters than
+// this, even when just clicking in the text field.
+static const int cMaxLen = 524288;
+
 static int numGraphemeClusters(const StringImpl* s)
 {
     if (!s)
@@ -107,7 +113,7 @@ void HTMLInputElement::init()
 {
     m_imageLoader = 0;
     m_type = TEXT;
-    m_maxLen = 1024;
+    m_maxLen = cMaxLen;
     m_size = 20;
     m_checked = false;
     m_defaultChecked = false;
@@ -609,9 +615,9 @@ void HTMLInputElement::parseMappedAttribute(MappedAttribute *attr)
         }
     } else if (attr->name() == maxlengthAttr) {
         int oldMaxLen = m_maxLen;
-        m_maxLen = !attr->isNull() ? attr->value().toInt() : 1024;
-        if (m_maxLen <= 0 || m_maxLen > 1024)
-            m_maxLen = 1024;
+        m_maxLen = !attr->isNull() ? attr->value().toInt() : cMaxLen;
+        if (m_maxLen <= 0 || m_maxLen > cMaxLen)
+            m_maxLen = cMaxLen;
         if (oldMaxLen != m_maxLen)
             recheckValue();
         setChanged();
index aba26b0e420e34761d5608b87767f05832e3b591..ed39e05211f05556b7c649d0ae54071ffc732ee0 100644 (file)
@@ -199,7 +199,7 @@ private:
     String m_value;
     String m_originalValue;
     int xPos;
-    short m_maxLen;
+    int m_maxLen;
     short m_size;
     short yPos;