Changeset 48449 in webkit


Ignore:
Timestamp:
Sep 16, 2009 7:13:49 PM (15 years ago)
Author:
eric@webkit.org
Message:

2009-09-15 Kent Tamura <tkent@chromium.org>

Reviewed by Eric Seidel.

<input maxlength=> should restrict only values specified by users.
https://bugs.webkit.org/show_bug.cgi?id=21271

  • fast/forms/input-appearance-maxlength-expected.txt:
  • fast/forms/input-appearance-maxlength.html:
  • fast/forms/input-maxlength-expected.txt:
  • fast/forms/input-maxlength.html:
  • fast/forms/input-text-maxlength-expected.txt: Added.
  • fast/forms/input-text-maxlength.html:
  • fast/forms/input-text-paste-maxlength-expected.txt: Added.
  • fast/forms/input-text-paste-maxlength.html:
  • platform/mac-leopard/fast/forms/input-text-maxlength-expected.checksum: Removed.
  • platform/mac-leopard/fast/forms/input-text-maxlength-expected.png: Removed.
  • platform/mac-leopard/fast/forms/input-text-maxlength-expected.txt: Removed.
  • platform/mac-leopard/fast/forms/input-text-paste-maxlength-expected.checksum: Removed.
  • platform/mac-leopard/fast/forms/input-text-paste-maxlength-expected.png: Removed.
  • platform/mac-leopard/fast/forms/input-text-paste-maxlength-expected.txt: Removed.
  • platform/mac/fast/forms/input-text-maxlength-expected.txt: Removed.
  • platform/mac/fast/forms/input-text-paste-maxlength-expected.txt: Removed.
  • platform/qt/fast/forms/input-text-maxlength-expected.txt: Removed.
  • platform/qt/fast/forms/input-text-paste-maxlength-expected.txt: Removed.
  • platform/win/fast/forms/input-text-maxlength-expected.txt: Removed.
  • platform/win/fast/forms/input-text-paste-maxlength-expected.txt: Removed.

2009-09-15 Kent Tamura <tkent@chromium.org>

Reviewed by Eric Seidel.

<input maxlength=> should restrict only values specified by users.
https://bugs.webkit.org/show_bug.cgi?id=21271

  • dom/InputElement.cpp: (WebCore::InputElement::setValueFromRenderer): (WebCore::InputElement::sanitizeValue): (WebCore::InputElement::sanitizeUserInputValue): Rename from constrainValue(). (WebCore::InputElement::handleBeforeTextInsertedEvent): (WebCore::InputElement::updateValueIfNeeded):
  • dom/InputElement.h:
  • html/HTMLInputElement.cpp: (WebCore::HTMLInputElement::setInputType): (WebCore::HTMLInputElement::value): (WebCore::HTMLInputElement::setValue): (WebCore::HTMLInputElement::sanitizeValue):
  • html/HTMLInputElement.h:
  • rendering/RenderTextControlSingleLine.cpp: (WebCore::RenderTextControlSingleLine::subtreeHasChanged):
  • wml/WMLInputElement.cpp: (WebCore::WMLInputElement::constrainValue):
  • wml/WMLInputElement.h: (WebCore::WMLInputElement::sanitizeValue):
Location:
trunk
Files:
2 added
12 deleted
15 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r48447 r48449  
     12009-09-15  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        <input maxlength=> should restrict only values specified by users.
     6        https://bugs.webkit.org/show_bug.cgi?id=21271
     7
     8        * fast/forms/input-appearance-maxlength-expected.txt:
     9        * fast/forms/input-appearance-maxlength.html:
     10        * fast/forms/input-maxlength-expected.txt:
     11        * fast/forms/input-maxlength.html:
     12        * fast/forms/input-text-maxlength-expected.txt: Added.
     13        * fast/forms/input-text-maxlength.html:
     14        * fast/forms/input-text-paste-maxlength-expected.txt: Added.
     15        * fast/forms/input-text-paste-maxlength.html:
     16        * platform/mac-leopard/fast/forms/input-text-maxlength-expected.checksum: Removed.
     17        * platform/mac-leopard/fast/forms/input-text-maxlength-expected.png: Removed.
     18        * platform/mac-leopard/fast/forms/input-text-maxlength-expected.txt: Removed.
     19        * platform/mac-leopard/fast/forms/input-text-paste-maxlength-expected.checksum: Removed.
     20        * platform/mac-leopard/fast/forms/input-text-paste-maxlength-expected.png: Removed.
     21        * platform/mac-leopard/fast/forms/input-text-paste-maxlength-expected.txt: Removed.
     22        * platform/mac/fast/forms/input-text-maxlength-expected.txt: Removed.
     23        * platform/mac/fast/forms/input-text-paste-maxlength-expected.txt: Removed.
     24        * platform/qt/fast/forms/input-text-maxlength-expected.txt: Removed.
     25        * platform/qt/fast/forms/input-text-paste-maxlength-expected.txt: Removed.
     26        * platform/win/fast/forms/input-text-maxlength-expected.txt: Removed.
     27        * platform/win/fast/forms/input-text-paste-maxlength-expected.txt: Removed.
     28
    1292009-09-16  Geoffrey Garen  <ggaren@apple.com>
    230
  • trunk/LayoutTests/fast/forms/input-appearance-maxlength-expected.txt

    r21687 r48449  
    1 This test changes the value of the text field by simulating typing, and then gets the value.
     1This test changes the value of the text field by simulating typing, and then gets the value.
     2
     3On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
    24
    35
    4 Test 1 Passed. Maxlength works for default value. Test 2 Passed. Maxlength works for inserted text.
     6PASS Maxlength shouldn't work for default value.
     7PASS Maxlength works for inserted text.
     8PASS successfullyParsed is true
     9
     10TEST COMPLETE
     11
  • trunk/LayoutTests/fast/forms/input-appearance-maxlength.html

    r21448 r48449  
     1<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
    12<html>
    23<head>
     4<script src="../../fast/js/resources/js-test-pre.js"></script>
     5</head>
     6<body>
     7<p id="description"></p>
     8<div id="console"></div>
     9
     10<input type="text" id="sp" style="-khtml-appearance:textfield" maxlength=5 value="123456"></input>
     11
    312<script>
     13description('This test changes the value of the text field by simulating typing, and then gets the value.');
    414
    5 function test()
    6 {
    7     var res = "";
    8     if (window.layoutTestController) {
    9         layoutTestController.dumpAsText();
    10     }
     15var input = document.getElementById('sp');
     16
     17if (input.value != "12345") {
     18    testPassed('Maxlength shouldn\'t work for default value.\n');
     19} else {
     20    testFailed('Maxlength unexpectedly works for default value.\n');
     21}
    1122   
    12     if (document.getElementById('sp').value == "12345") {
    13         res+= "Test 1 Passed.  Maxlength works for default value.\n";
    14     } else {
    15         res+= "Test 1 Failed.  Maxlength does not work for default value.\n";
    16     }
     23input.value = "123";
     24input.setSelectionRange(0, 3);
     25input.focus();
     26document.execCommand("InsertText", false, 'abcd');
     27document.execCommand("InsertText", false, 'efghi');
    1728   
    18     document.getElementById('sp').value = "123";
    19    
    20     document.getElementById('sp').setSelectionRange(0, 3);
    21     document.getElementById('sp').focus();
    22     document.execCommand("InsertText", false, 'abcd');
    23     document.execCommand("InsertText", false, 'efghi');
    24    
    25     if (document.getElementById('sp').value == "abcde") {
    26         res+= "Test 2 Passed.  Maxlength works for inserted text.\n";
    27     } else {
    28         res+= "Test 2 Failed.  Maxlength does not work for inserted text.\n";
    29     }
    30    
    31     document.getElementById('result').innerHTML = res;
     29if (input.value == "abcde") {
     30    testPassed('Maxlength works for inserted text.\n');
     31} else {
     32    testFailed('Maxlength does not work for inserted text.\n');
    3233}
    3334
     35var successfullyParsed = true;
    3436</script>
    35 </head>
    36 <body onload="test()">
    37 This test changes the value of the text field by simulating typing, and then gets the value.
    38 <br><br>
    39 <input type="text" id="sp" style="-khtml-appearance:textfield" maxlength=5 value="123456"></input>
    40 <div id="result">
    41 </div>
     37<script src="../../fast/js/resources/js-test-post.js"></script>
    4238</body>
    4339</html>
  • trunk/LayoutTests/fast/forms/input-maxlength-expected.txt

    r24037 r48449  
    11This page tests that the maxlength attribute of the <input> element works correctly. http://bugs.webkit.org/show_bug.cgi?id=14388
    22
     3Attempting to insert 0 characters with maxLength = -1.
     4PASS
     5Attempting to insert 0 characters with maxLength = 100.
     6PASS
     7Attempting to insert 0 characters with maxLength = 524288.
     8PASS
     9Attempting to insert 0 characters with maxLength = 600000.
     10PASS
     11Attempting to insert 5 characters with maxLength = -1.
     12PASS
     13Attempting to insert 5 characters with maxLength = 100.
     14PASS
     15Attempting to insert 5 characters with maxLength = 524288.
     16PASS
     17Attempting to insert 5 characters with maxLength = 600000.
     18PASS
     19Attempting to insert 100 characters with maxLength = -1.
     20PASS
     21Attempting to insert 100 characters with maxLength = 100.
     22PASS
     23Attempting to insert 100 characters with maxLength = 524288.
     24PASS
     25Attempting to insert 100 characters with maxLength = 600000.
     26PASS
     27Attempting to insert 101 characters with maxLength = -1.
     28PASS
     29Attempting to insert 101 characters with maxLength = 100.
     30PASS
     31Attempting to insert 101 characters with maxLength = 524288.
     32PASS
     33Attempting to insert 101 characters with maxLength = 600000.
     34PASS
     35Attempting to insert 200 characters with maxLength = -1.
     36PASS
     37Attempting to insert 200 characters with maxLength = 100.
     38PASS
     39Attempting to insert 200 characters with maxLength = 524288.
     40PASS
     41Attempting to insert 200 characters with maxLength = 600000.
     42PASS
     43Attempting to insert 524287 characters with maxLength = -1.
     44PASS
     45Attempting to insert 524287 characters with maxLength = 100.
     46PASS
     47Attempting to insert 524287 characters with maxLength = 524288.
     48PASS
     49Attempting to insert 524287 characters with maxLength = 600000.
     50PASS
     51Attempting to insert 524288 characters with maxLength = -1.
     52PASS
     53Attempting to insert 524288 characters with maxLength = 100.
     54PASS
     55Attempting to insert 524288 characters with maxLength = 524288.
     56PASS
     57Attempting to insert 524288 characters with maxLength = 600000.
     58PASS
     59Attempting to insert 524289 characters with maxLength = -1.
     60PASS
     61Attempting to insert 524289 characters with maxLength = 100.
     62PASS
     63Attempting to insert 524289 characters with maxLength = 524288.
     64PASS
     65Attempting to insert 524289 characters with maxLength = 600000.
     66PASS
     67Attempting to insert 530000 characters with maxLength = -1.
     68PASS
     69Attempting to insert 530000 characters with maxLength = 100.
     70PASS
     71Attempting to insert 530000 characters with maxLength = 524288.
     72PASS
     73Attempting to insert 530000 characters with maxLength = 600000.
     74PASS
     75PASS successfullyParsed is true
    376
    4 Attempting to insert 0 characters with maxLength = -1.
    5 PASS
    6 Attempting to insert 0 characters with maxLength = 100.
    7 PASS
    8 Attempting to insert 0 characters with maxLength = 524288.
    9 PASS
    10 Attempting to insert 0 characters with maxLength = 600000.
    11 PASS
    12 Attempting to insert 5 characters with maxLength = -1.
    13 PASS
    14 Attempting to insert 5 characters with maxLength = 100.
    15 PASS
    16 Attempting to insert 5 characters with maxLength = 524288.
    17 PASS
    18 Attempting to insert 5 characters with maxLength = 600000.
    19 PASS
    20 Attempting to insert 100 characters with maxLength = -1.
    21 PASS
    22 Attempting to insert 100 characters with maxLength = 100.
    23 PASS
    24 Attempting to insert 100 characters with maxLength = 524288.
    25 PASS
    26 Attempting to insert 100 characters with maxLength = 600000.
    27 PASS
    28 Attempting to insert 101 characters with maxLength = -1.
    29 PASS
    30 Attempting to insert 101 characters with maxLength = 100.
    31 PASS
    32 Attempting to insert 101 characters with maxLength = 524288.
    33 PASS
    34 Attempting to insert 101 characters with maxLength = 600000.
    35 PASS
    36 Attempting to insert 200 characters with maxLength = -1.
    37 PASS
    38 Attempting to insert 200 characters with maxLength = 100.
    39 PASS
    40 Attempting to insert 200 characters with maxLength = 524288.
    41 PASS
    42 Attempting to insert 200 characters with maxLength = 600000.
    43 PASS
    44 Attempting to insert 524287 characters with maxLength = -1.
    45 PASS
    46 Attempting to insert 524287 characters with maxLength = 100.
    47 PASS
    48 Attempting to insert 524287 characters with maxLength = 524288.
    49 PASS
    50 Attempting to insert 524287 characters with maxLength = 600000.
    51 PASS
    52 Attempting to insert 524288 characters with maxLength = -1.
    53 PASS
    54 Attempting to insert 524288 characters with maxLength = 100.
    55 PASS
    56 Attempting to insert 524288 characters with maxLength = 524288.
    57 PASS
    58 Attempting to insert 524288 characters with maxLength = 600000.
    59 PASS
    60 Attempting to insert 524289 characters with maxLength = -1.
    61 PASS
    62 Attempting to insert 524289 characters with maxLength = 100.
    63 PASS
    64 Attempting to insert 524289 characters with maxLength = 524288.
    65 PASS
    66 Attempting to insert 524289 characters with maxLength = 600000.
    67 PASS
    68 Attempting to insert 530000 characters with maxLength = -1.
    69 PASS
    70 Attempting to insert 530000 characters with maxLength = 100.
    71 PASS
    72 Attempting to insert 530000 characters with maxLength = 524288.
    73 PASS
    74 Attempting to insert 530000 characters with maxLength = 600000.
    75 PASS
     77TEST COMPLETE
    7678
  • trunk/LayoutTests/fast/forms/input-maxlength.html

    r24037 r48449  
     1<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
     2<html>
     3<head>
     4<script src="../../fast/js/resources/js-test-pre.js"></script>
     5</head>
     6<body>
    17<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>
     8<div id="console"></div>
     9
    210<input id="input">
    3 <pre id="log"></pre>
     11
    412<script>
    5     function log(msg)
    6     {
    7         document.getElementById("log").appendChild(document.createTextNode(msg + "\n"));
    8     }
    9 
    10     if (window.layoutTestController)
    11         layoutTestController.dumpAsText();
    12 
     13    var implicitMaxLength = 524288;
    1314    var testString = "";
    1415    var input = document.getElementById("input");
     
    1617    function attempt(length, expected)
    1718    {
    18         log("Attempting to insert " + length + " characters with maxLength = " + input.getAttribute("maxlength") + ".");
     19        debug("Attempting to insert " + length + " characters with maxLength = " + input.getAttribute("maxlength") + ".");
    1920
    2021        if (testString.length > length)
     
    2526
    2627        input.value = testString;
    27 
    2828        if (input.value.length == expected)
    29             log("PASS");
     29            testPassed("");
    3030        else
    31             log("FAIL: Expected " + expected + " characters to be inserted, but " + input.value.length + " characters were actually inserted.");
     31            testFailed("Expected " + domExpected + " characters to be inserted, but " + input.value.length + " characters were actually inserted.");
    3232    }
    33 
    34     var implicitMaxLength = 524288;
    3533
    3634    var stringLengthsToTest = [0, 5, 100, 101, 200, 524287, 524288, 524289, 530000];
     
    4240            var maxLength = maxLengthsToTest[j];
    4341            input.setAttribute("maxlength", maxLength);
    44             if (maxLength < 0 || maxLength > implicitMaxLength)
    45                 maxLength = implicitMaxLength;
    46             var expected = Math.min(stringLength, maxLength);
     42            var expected = Math.min(stringLength, implicitMaxLength);
    4743            attempt(stringLength, expected);
    4844        }
    4945    }
     46
     47    var successfullyParsed = true;
    5048</script>
     49<script src="../../fast/js/resources/js-test-post.js"></script>
     50</body>
     51</html>
  • trunk/LayoutTests/fast/forms/input-text-maxlength.html

    r13743 r48449  
    1 <style>
    2 table { font: 11px 'Lucida Grande' }
    3 .result { color: GrayText; padding-left: 4px; padding-right: 8px }
    4 .result:before { content: "expected: " }
    5 </style>
     1<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
     2<html>
     3<head>
     4<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
     5<script src="../../fast/js/resources/js-test-pre.js"></script>
     6</head>
     7<body>
     8<p id="description"></p>
     9<div id="console"></div>
    610
    7 <table>
    8 
    9 <tr><td><input type="text" size="5" value="12345" maxlength="4"></td>
    10 <td class="result">1234</td>
    11 <td class="description">maxlength and value that violates it, maxlength first</td></tr>
    12 
    13 <tr><td><input type="text" size="5" maxlength="4" value="12345"></td>
    14 <td class="result">1234</td>
    15 <td class="description">maxlength and value that violates it, value first</td></tr>
    16 
    17 <tr><td><input type="text" id="f" size="5" maxlength="4" value="123"></td>
    18 <td class="result">1234</td>
    19 <td class="description">set value attribute that violates maxlength</td></tr>
    20 
    21 <tr><td><input type="text" id="e" size="5" maxlength="4" value="123"></td>
    22 <td class="result">1234</td>
    23 <td class="description">set value property that violates maxlength</td></tr>
    24 
    25 <tr><td><input type="text" id="d" size="5" value="12345"></td>
    26 <td class="result">1234</td>
    27 <td class="description">set maxlength attribute that is smaller than initial value</td></tr>
    28 
    29 <tr><td><input type="text" id="c" size="5" value="12345"></td>
    30 <td class="result">1234</td>
    31 <td class="description">set maxLength property that is smaller than initial value</td></tr>
    32 
    33 <tr><td><input type="text" size="5" value="12x&#x305;&#x332;45" maxlength="4"></td>
    34 <td class="result">12x&#x305;&#x332;4</td>
    35 <td class="description">maxlength and value that violates it, maxlength first</td></tr>
    36 
    37 <tr><td><input type="text" size="5" maxlength="4" value="12x&#x305;&#x332;45"></td>
    38 <td class="result">12x&#x305;&#x332;4</td>
    39 <td class="description">maxlength and value that violates it, value first</td></tr>
    40 
    41 <tr><td><input type="text" id="j" size="5" maxlength="4" value="123"></td>
    42 <td class="result">12x&#x305;&#x332;4</td>
    43 <td class="description">set value attribute that violates maxlength</td></tr>
    44 
    45 <tr><td><input type="text" id="i" size="5" maxlength="4" value="123"></td>
    46 <td class="result">12x&#x305;&#x332;4</td>
    47 <td class="description">set value property that violates maxlength</td></tr>
    48 
    49 <tr><td><input type="text" id="h" size="5" value="12x&#x305;&#x332;45"></td>
    50 <td class="result">12x&#x305;&#x332;4</td>
    51 <td class="description">set maxlength attribute that is smaller than initial value</td></tr>
    52 
    53 <tr><td><input type="text" id="g" size="5" value="12x&#x305;&#x332;45"></td>
    54 <td class="result">12x&#x305;&#x332;4</td>
    55 <td class="description">set maxLength property that is smaller than initial value</td></tr>
    56 
    57 </table>
     11<input type="text" size="5" value="12345" maxlength="4" id="input1">
     12<input type="text" size="5" maxlength="4" value="12345" id="input2">
     13<input type="text" id="f" size="5" maxlength="4" value="123">
     14<input type="text" id="e" size="5" maxlength="4" value="123">
     15<input type="text" id="d" size="5" value="12345">
     16<input type="text" id="c" size="5" value="12345">
     17<input type="text" size="5" value="12x&#x305;&#x332;45" maxlength="4" id="input7">
     18<input type="text" size="5" maxlength="4" value="12x&#x305;&#x332;45" id="input8">
     19<input type="text" id="j" size="5" maxlength="4" value="123">
     20<input type="text" id="i" size="5" maxlength="4" value="123">
     21<input type="text" id="h" size="5" value="12x&#x305;&#x332;45">
     22<input type="text" id="g" size="5" value="12x&#x305;&#x332;45">
    5823
    5924<script>
     25function domValueOf(id) {
     26    return document.getElementById(id).value;
     27}
     28function visibleValueOf(id) {
     29    var el = document.getElementById(id);
     30    el.focus();
     31    document.execCommand('SelectAll');
     32    return document.getSelection().toString();
     33}
     34
    6035var fancyX = "x" + String.fromCharCode(0x305) + String.fromCharCode(0x332);
     36
     37debug('maxlength and value that violates it, maxlength first');
     38shouldBe('domValueOf("input1")', '"12345"');
     39shouldBe('visibleValueOf("input1")', '"12345"');
     40
     41debug('maxlength and value that violates it, maxlength first');
     42shouldBe('domValueOf("input2")', '"12345"');
     43shouldBe('visibleValueOf("input2")', '"12345"');
     44
     45debug('set value attribute that violates maxlength');
     46document.getElementById("f").setAttribute('value', '12345');
     47shouldBe('domValueOf("f")', '"12345"');
     48shouldBe('visibleValueOf("input2")', '"12345"');
     49
     50debug('set value property that violates maxlength');
     51document.getElementById("e").value = '12345';
     52shouldBe('domValueOf("e")', '"12345"');
     53shouldBe('visibleValueOf("e")', '"12345"');
     54
     55debug('set maxlength attribute that is smaller than initial value');
     56document.getElementById("d").setAttribute('maxlength', 4);
     57shouldBe('domValueOf("d")', '"12345"');
     58shouldBe('visibleValueOf("d")', '"12345"');
     59
     60debug('set maxLength property that is smaller than initial value');
    6161document.getElementById("c").maxLength = 4;
    62 document.getElementById("d").setAttribute('maxlength', 4);
    63 document.getElementById("e").value = '12345';
    64 document.getElementById("f").setAttribute('value', '12345');
     62shouldBe('domValueOf("c")', '"12345"');
     63shouldBe('visibleValueOf("c")', '"12345"');
     64
     65debug('maxlength and value that violates it, maxlength first');
     66shouldBe('domValueOf("input7")', '"12" + fancyX + "45"');
     67shouldBe('visibleValueOf("input7")', '"12" + fancyX + "45"');
     68
     69debug('maxlength and value that violates it, value first');
     70shouldBe('domValueOf("input8")', '"12" + fancyX + "45"');
     71shouldBe('visibleValueOf("input8")', '"12" + fancyX + "45"');
     72
     73debug('set value attribute that violates maxlength');
     74document.getElementById("j").setAttribute('value', '12' + fancyX + '45');
     75shouldBe('domValueOf("j")', '"12" + fancyX + "45"');
     76shouldBe('visibleValueOf("j")', '"12" + fancyX + "45"');
     77
     78debug('set value property that violates maxlength');
     79document.getElementById("i").value = '12' + fancyX + '45';
     80shouldBe('domValueOf("i")', '"12" + fancyX + "45"');
     81shouldBe('visibleValueOf("i")', '"12" + fancyX + "45"');
     82
     83debug('set maxlength attribute that is smaller than initial value');
     84document.getElementById("h").setAttribute('maxlength', 4);
     85shouldBe('domValueOf("h")', '"12" + fancyX + "45"');
     86shouldBe('visibleValueOf("h")', '"12" + fancyX + "45"');
     87
     88debug('set maxLength property that is smaller than initial value');
    6589document.getElementById("g").maxLength = 4;
    66 document.getElementById("h").setAttribute('maxlength', 4);
    67 document.getElementById("i").value = '12' + fancyX + '45';
    68 document.getElementById("j").setAttribute('value', '12' + fancyX + '45');
     90shouldBe('domValueOf("g")', '"12" + fancyX + "45"');
     91shouldBe('visibleValueOf("g")', '"12" + fancyX + "45"');
     92
     93var successfullyParsed = true;
    6994</script>
     95<script src="../../fast/js/resources/js-test-post.js"></script>
     96</body>
     97</html>
  • trunk/LayoutTests/fast/forms/input-text-paste-maxlength.html

    r13743 r48449  
    1 <style>
    2 table { font: 11px 'Lucida Grande' }
    3 .result { color: GrayText; padding-left: 4px; padding-right: 8px }
    4 .result:before { content: "expected: " }
    5 </style>
     1<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
     2<html>
     3<head>
     4<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
     5<script src="../../fast/js/resources/js-test-pre.js"></script>
     6</head>
     7<body>
     8<p id="description"></p>
     9<div id="console"></div>
    610
    7 <table>
    8 
    9 <tr><td><input type="text" id="f" size="5" maxlength="4"></td>
    10 <td class="result">123</td>
    11 <td class="description">set value attribute that violates maxlength (with pasted value)</td></tr>
    12 
    13 <tr><td><input type="text" id="e" size="5" maxlength="4"></td>
    14 <td class="result">1234</td>
    15 <td class="description">set value property that violates maxlength (with pasted value)</td></tr>
    16 
    17 <tr><td><input type="text" id="d" size="5"></td>
    18 <td class="result">1234</td>
    19 <td class="description">set maxlength attribute that is smaller than pasted value</td></tr>
    20 
    21 <tr><td><input type="text" id="c" size="5"></td>
    22 <td class="result">1234</td>
    23 <td class="description">set maxLength property that is smaller than pasted value</td></tr>
    24 
    25 <tr><td><input type="text" id="j" size="5" maxlength="4"></td>
    26 <td class="result">123</td>
    27 <td class="description">set value attribute that violates maxlength (with pasted value)</td></tr>
    28 
    29 <tr><td><input type="text" id="i" size="5" maxlength="4"></td>
    30 <td class="result">12x&#x305;&#x332;4</td>
    31 <td class="description">set value property that violates maxlength (with pasted value)</td></tr>
    32 
    33 <tr><td><input type="text" id="h" size="5"></td>
    34 <td class="result">12x&#x305;&#x332;4</td>
    35 <td class="description">set maxlength attribute that is smaller than pasted value</td></tr>
    36 
    37 <tr><td><input type="text" id="g" size="5"></td>
    38 <td class="result">12x&#x305;&#x332;4</td>
    39 <td class="description">set maxLength property that is smaller than pasted value</td></tr>
    40 
    41 <tr><td><input type="text" id="k" size="5" maxlength="4"></td>
    42 <td class="result">12x&#x305;&#x332;4</td>
    43 <td class="description">pasting too much text</td></tr>
    44 
    45 </table>
     11<input type="text" id="f" size="5" maxlength="4">
     12<input type="text" id="e" size="5" maxlength="4">
     13<input type="text" id="d" size="5">
     14<input type="text" id="c" size="5">
     15<input type="text" id="j" size="5" maxlength="4">
     16<input type="text" id="i" size="5" maxlength="4">
     17<input type="text" id="h" size="5">
     18<input type="text" id="g" size="5">
     19<input type="text" id="k" size="5" maxlength="4">
    4620
    4721<script>
     22function domValueOf(id) {
     23    return document.getElementById(id).value;
     24}
     25function visibleValueOf(id) {
     26    var el = document.getElementById(id);
     27    el.focus();
     28    document.execCommand('SelectAll');
     29    return document.getSelection().toString();
     30}
     31
    4832var fancyX = "x" + String.fromCharCode(0x305) + String.fromCharCode(0x332);
     33
     34debug("set value attribute that violates maxlength (with pasted value)");
     35document.getElementById("f").focus();
     36document.execCommand("InsertHTML", false, "123");
     37document.getElementById("f").setAttribute('value', '12345');
     38shouldBe("domValueOf('f')", "'123'");  // setAttribute() doesn't change the value because the value is dirty.
     39shouldBe("visibleValueOf('f')", "'123'");
     40
     41debug("set value property that violates maxlength (with pasted value)");
     42document.getElementById("e").focus();
     43document.execCommand("InsertHTML", false, "123");
     44document.getElementById("e").value = '12345';
     45shouldBe("domValueOf('e')", "'12345'");  // Unlike setAttribute(), .value property changes the value.
     46shouldBe("visibleValueOf('e')", "'12345'");
     47
     48debug("set maxlength attribute that is smaller than pasted value");
     49document.getElementById("d").focus();
     50document.execCommand("InsertHTML", false, "12345");
     51document.getElementById("d").setAttribute('maxlength', 4);
     52shouldBe("domValueOf('d')", "'12345'");
     53shouldBe("visibleValueOf('d')", "'12345'");
     54
     55debug("set maxLength property that is smaller than pasted value");
    4956document.getElementById("c").focus();
    5057document.execCommand("InsertHTML", false, "12345");
    5158document.getElementById("c").maxLength = 4;
    52 document.getElementById("d").focus();
    53 document.execCommand("InsertHTML", false, "12345");
    54 document.getElementById("d").setAttribute('maxlength', 4);
    55 document.getElementById("e").focus();
     59shouldBe("domValueOf('c')", "'12345'");
     60shouldBe("visibleValueOf('c')", "'12345'");
     61
     62debug("set value attribute that violates maxlength (with pasted value)");
     63document.getElementById("j").focus();
    5664document.execCommand("InsertHTML", false, "123");
    57 document.getElementById("e").value = '12345';
    58 document.getElementById("f").focus();
     65document.getElementById("j").setAttribute('value', '12' + fancyX + '45');
     66shouldBe("domValueOf('j')", "'123'");
     67shouldBe("visibleValueOf('j')", "'123'");
     68
     69debug("set value property that violates maxlength (with pasted value)");
     70document.getElementById("i").focus();
    5971document.execCommand("InsertHTML", false, "123");
    60 document.getElementById("f").setAttribute('value', '12345');
     72document.getElementById("i").value = '12' + fancyX + '45';
     73shouldBe("domValueOf('i')", "'12' + fancyX + '45'");
     74shouldBe("visibleValueOf('i')", "'12' + fancyX + '45'");
     75
     76debug("set maxlength attribute that is smaller than pasted value");
     77document.getElementById("h").focus();
     78document.execCommand("InsertHTML", false, "12x&#x305;&#x332;45");
     79document.getElementById("h").setAttribute('maxlength', 4);
     80shouldBe("domValueOf('h')", "'12' + fancyX + '45'");
     81shouldBe("visibleValueOf('h')", "'12' + fancyX + '45'");
     82
     83debug("set maxLength property that is smaller than pasted value");
    6184document.getElementById("g").focus();
    6285document.execCommand("InsertHTML", false, "12x&#x305;&#x332;45");
    6386document.getElementById("g").maxLength = 4;
    64 document.getElementById("h").focus();
    65 document.execCommand("InsertHTML", false, "12x&#x305;&#x332;45");
    66 document.getElementById("h").setAttribute('maxlength', 4);
    67 document.getElementById("i").focus();
    68 document.execCommand("InsertHTML", false, "123");
    69 document.getElementById("i").value = '12' + fancyX + '45';
    70 document.getElementById("j").focus();
    71 document.execCommand("InsertHTML", false, "123");
    72 document.getElementById("j").setAttribute('value', '12' + fancyX + '45');
     87shouldBe("domValueOf('g')", "'12' + fancyX + '45'");
     88shouldBe("visibleValueOf('g')", "'12' + fancyX + '45'");
     89
     90debug("pasting too much text");
    7391document.getElementById("k").focus();
    7492document.execCommand("InsertHTML", false, "12x&#x305;&#x332;45");
    75 document.getElementById("k").blur();
     93shouldBe("domValueOf('k')", "'12' + fancyX + '4'");
     94shouldBe("visibleValueOf('k')", "'12' + fancyX + '4'");
     95
     96var successfullyParsed = true;
    7697</script>
     98<script src="../../fast/js/resources/js-test-post.js"></script>
     99</body>
     100</html>
  • trunk/WebCore/ChangeLog

    r48448 r48449  
     12009-09-15  Kent Tamura  <tkent@chromium.org>
     2
     3        Reviewed by Eric Seidel.
     4
     5        <input maxlength=> should restrict only values specified by users.
     6        https://bugs.webkit.org/show_bug.cgi?id=21271
     7
     8        * dom/InputElement.cpp:
     9        (WebCore::InputElement::setValueFromRenderer):
     10        (WebCore::InputElement::sanitizeValue):
     11        (WebCore::InputElement::sanitizeUserInputValue): Rename from constrainValue().
     12        (WebCore::InputElement::handleBeforeTextInsertedEvent):
     13        (WebCore::InputElement::updateValueIfNeeded):
     14        * dom/InputElement.h:
     15        * html/HTMLInputElement.cpp:
     16        (WebCore::HTMLInputElement::setInputType):
     17        (WebCore::HTMLInputElement::value):
     18        (WebCore::HTMLInputElement::setValue):
     19        (WebCore::HTMLInputElement::sanitizeValue):
     20        * html/HTMLInputElement.h:
     21        * rendering/RenderTextControlSingleLine.cpp:
     22        (WebCore::RenderTextControlSingleLine::subtreeHasChanged):
     23        * wml/WMLInputElement.cpp:
     24        (WebCore::WMLInputElement::constrainValue):
     25        * wml/WMLInputElement.h:
     26        (WebCore::WMLInputElement::sanitizeValue):
     27
    1282009-09-16  Enrica Casucci  <enrica@apple.com>
    229
  • trunk/WebCore/dom/InputElement.cpp

    r48011 r48449  
    4747
    4848// FIXME: According to HTML4, the length attribute's value can be arbitrarily
    49 // large. However, due to http://bugs.webkit.org/show_bugs.cgi?id=14536 things
     49// large. However, due to https://bugs.webkit.org/show_bug.cgi?id=14536 things
    5050// get rather sluggish when a text field has a larger number of characters than
    5151// this, even when just clicking in the text field.
     
    139139void InputElement::setValueFromRenderer(InputElementData& data, InputElement* inputElement, Element* element, const String& value)
    140140{
    141     // Renderer and our event handler are responsible for constraining values.
    142     ASSERT(value == inputElement->constrainValue(value) || inputElement->constrainValue(value).isEmpty());
     141    // Renderer and our event handler are responsible for sanitizing values.
     142    ASSERT(value == inputElement->sanitizeValue(value) || inputElement->sanitizeValue(value).isEmpty());
    143143
    144144    if (inputElement->isTextField())
     
    177177}
    178178
    179 String InputElement::constrainValue(const InputElement* inputElement, const String& proposedValue, int maxLength)
    180 {
     179String InputElement::sanitizeValue(const InputElement* inputElement, const String& proposedValue)
     180{
     181    return InputElement::sanitizeUserInputValue(inputElement, proposedValue, s_maximumLength);
     182}
     183
     184String InputElement::sanitizeUserInputValue(const InputElement* inputElement, const String& proposedValue, int maxLength)
     185{
     186    if (!inputElement->isTextField())
     187        return proposedValue;
     188
    181189    String string = proposedValue;
    182     if (!inputElement->isTextField())
    183         return string;
    184 
    185190    string.replace("\r\n", " ");
    186191    string.replace('\r', ' ');
    187192    string.replace('\n', ' ');
    188    
     193
    189194    StringImpl* s = string.impl();
    190195    int newLength = numCharactersInGraphemeClusters(s, maxLength);
     
    225230
    226231    // We use RenderTextControlSingleLine::text() instead of InputElement::value()
    227     // because they can be mismatched by constrainValue() in
    228     // RenderTextControlSingleLine::subtreeHasChanged() in a case of IME input.
     232    // because they can be mismatched by sanitizeValue() in
     233    // RenderTextControlSingleLine::subtreeHasChanged() in some cases.
    229234    int oldLength = numGraphemeClusters(toRenderTextControlSingleLine(element->renderer())->text().impl());
    230235
     
    239244    // Truncate the inserted text to avoid violating the maxLength and other constraints.
    240245    BeforeTextInsertedEvent* textEvent = static_cast<BeforeTextInsertedEvent*>(event);
    241     textEvent->setText(constrainValue(inputElement, textEvent->text(), appendableLength));
     246    textEvent->setText(sanitizeUserInputValue(inputElement, textEvent->text(), appendableLength));
    242247}
    243248
     
    268273{
    269274    String oldValue = data.value();
    270     String newValue = inputElement->constrainValue(oldValue);
     275    String newValue = sanitizeValue(inputElement, oldValue);
    271276    if (newValue != oldValue)
    272277        inputElement->setValue(newValue);
  • trunk/WebCore/dom/InputElement.h

    r48011 r48449  
    5555    virtual void setPlaceholder(const String&) = 0;
    5656
    57     virtual String constrainValue(const String&) const = 0;
     57    virtual String sanitizeValue(const String&) const = 0;
    5858    virtual void setValueFromRenderer(const String&) = 0;
    5959
     
    7373    static void aboutToUnload(InputElement*, Element*);
    7474    static void setValueFromRenderer(InputElementData&, InputElement*, Element*, const String&);
    75     static String constrainValue(const InputElement*, const String& proposedValue, int maxLength);
     75    // Replaces CRs and LFs, shrinks the value for s_maximumLength.
     76    // This should be applied to values from the HTML value attribute and the DOM value property.
     77    static String sanitizeValue(const InputElement*, const String&);
     78    // Replaces CRs and LFs, shrinks the value for the specified maximum length.
     79    // This should be applied to values specified by users.
     80    static String sanitizeUserInputValue(const InputElement*, const String&, int);
    7681    static void handleBeforeTextInsertedEvent(InputElementData&, InputElement*, Element*, Event*);
    7782    static void parseSizeAttribute(InputElementData&, Element*, MappedAttribute*);
  • trunk/WebCore/html/HTMLInputElement.cpp

    r48244 r48449  
    355355            }
    356356            if (!didStoreValue && willStoreValue)
    357                 m_data.setValue(constrainValue(getAttribute(valueAttr)));
     357                m_data.setValue(sanitizeValue(getAttribute(valueAttr)));
    358358            else
    359359                InputElement::updateValueIfNeeded(m_data, this);
     
    10541054    String value = m_data.value();
    10551055    if (value.isNull()) {
    1056         value = constrainValue(getAttribute(valueAttr));
     1056        value = sanitizeValue(getAttribute(valueAttr));
    10571057
    10581058        // If no attribute exists, then just use "on" or "" based off the checked() state of the control.
     
    11101110            m_fileList->clear();
    11111111        else {
    1112             m_data.setValue(constrainValue(value));
     1112            m_data.setValue(sanitizeValue(value));
    11131113            if (isTextField()) {
    11141114                InputElement::updatePlaceholderVisibility(this, this);
     
    11211121        setNeedsStyleRecalc();
    11221122    } else
    1123         setAttribute(valueAttr, constrainValue(value));
     1123        setAttribute(valueAttr, sanitizeValue(value));
    11241124   
    11251125    if (isTextField()) {
     
    16691669}
    16701670
    1671 String HTMLInputElement::constrainValue(const String& proposedValue) const
    1672 {
    1673     return InputElement::constrainValue(this, proposedValue, m_data.maxLength());
     1671String HTMLInputElement::sanitizeValue(const String& proposedValue) const
     1672{
     1673    if (isTextField())
     1674        return InputElement::sanitizeValue(this, proposedValue);
     1675    return proposedValue;
    16741676}
    16751677
  • trunk/WebCore/html/HTMLInputElement.h

    r48163 r48449  
    223223    VisibleSelection selection() const;
    224224
    225     virtual String constrainValue(const String& proposedValue) const;
     225    virtual String sanitizeValue(const String&) const;
    226226
    227227    virtual void documentDidBecomeActive();
  • trunk/WebCore/rendering/RenderTextControlSingleLine.cpp

    r48370 r48449  
    156156
    157157    InputElement* input = inputElement();
    158     input->setValueFromRenderer(input->constrainValue(text()));
     158    // We don't need to call sanitizeUserInputValue() function here because
     159    // InputElement::handleBeforeTextInsertedEvent() has already called
     160    // sanitizeUserInputValue().
     161    // sanitizeValue() is needed because IME input doesn't dispatch BeforeTextInsertedEvent.
     162    input->setValueFromRenderer(input->sanitizeValue(text()));
    159163
    160164    if (m_cancelButton)
  • trunk/WebCore/wml/WMLInputElement.cpp

    r48011 r48449  
    310310String WMLInputElement::constrainValue(const String& proposedValue) const
    311311{
    312     return InputElement::constrainValue(this, proposedValue, m_data.maxLength());
     312    return InputElement::sanitizeUserInputValue(this, proposedValue, m_data.maxLength());
    313313}
    314314
  • trunk/WebCore/wml/WMLInputElement.h

    r44480 r48449  
    8080    virtual void cacheSelection(int start, int end);
    8181
    82     virtual String constrainValue(const String& proposedValue) const;
     82    virtual String sanitizeValue(const String& proposedValue) const { return constrainValue(proposedValue); }
    8383
    8484    virtual void documentDidBecomeActive();
     
    9797    String validateInputMask(const String&);
    9898    unsigned cursorPositionToMaskIndex(unsigned);
     99    String constrainValue(const String&) const;
    99100
    100101    InputElementData m_data;
Note: See TracChangeset for help on using the changeset viewer.