Changeset 48449 in webkit
- Timestamp:
- Sep 16, 2009 7:13:49 PM (15 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 12 deleted
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r48447 r48449 1 2009-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 1 29 2009-09-16 Geoffrey Garen <ggaren@apple.com> 2 30 -
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. 1 This test changes the value of the text field by simulating typing, and then gets the value. 2 3 On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE". 2 4 3 5 4 Test 1 Passed. Maxlength works for default value. Test 2 Passed. Maxlength works for inserted text. 6 PASS Maxlength shouldn't work for default value. 7 PASS Maxlength works for inserted text. 8 PASS successfullyParsed is true 9 10 TEST COMPLETE 11 -
trunk/LayoutTests/fast/forms/input-appearance-maxlength.html
r21448 r48449 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> 1 2 <html> 2 3 <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 3 12 <script> 13 description('This test changes the value of the text field by simulating typing, and then gets the value.'); 4 14 5 function test() 6 { 7 var res = ""; 8 if (window.layoutTestController) { 9 layoutTestController.dumpAsText(); 10 } 15 var input = document.getElementById('sp'); 16 17 if (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 } 11 22 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 } 23 input.value = "123"; 24 input.setSelectionRange(0, 3); 25 input.focus(); 26 document.execCommand("InsertText", false, 'abcd'); 27 document.execCommand("InsertText", false, 'efghi'); 17 28 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; 29 if (input.value == "abcde") { 30 testPassed('Maxlength works for inserted text.\n'); 31 } else { 32 testFailed('Maxlength does not work for inserted text.\n'); 32 33 } 33 34 35 var successfullyParsed = true; 34 36 </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> 42 38 </body> 43 39 </html> -
trunk/LayoutTests/fast/forms/input-maxlength-expected.txt
r24037 r48449 1 1 This page tests that the maxlength attribute of the <input> element works correctly. http://bugs.webkit.org/show_bug.cgi?id=14388 2 2 3 Attempting to insert 0 characters with maxLength = -1. 4 PASS 5 Attempting to insert 0 characters with maxLength = 100. 6 PASS 7 Attempting to insert 0 characters with maxLength = 524288. 8 PASS 9 Attempting to insert 0 characters with maxLength = 600000. 10 PASS 11 Attempting to insert 5 characters with maxLength = -1. 12 PASS 13 Attempting to insert 5 characters with maxLength = 100. 14 PASS 15 Attempting to insert 5 characters with maxLength = 524288. 16 PASS 17 Attempting to insert 5 characters with maxLength = 600000. 18 PASS 19 Attempting to insert 100 characters with maxLength = -1. 20 PASS 21 Attempting to insert 100 characters with maxLength = 100. 22 PASS 23 Attempting to insert 100 characters with maxLength = 524288. 24 PASS 25 Attempting to insert 100 characters with maxLength = 600000. 26 PASS 27 Attempting to insert 101 characters with maxLength = -1. 28 PASS 29 Attempting to insert 101 characters with maxLength = 100. 30 PASS 31 Attempting to insert 101 characters with maxLength = 524288. 32 PASS 33 Attempting to insert 101 characters with maxLength = 600000. 34 PASS 35 Attempting to insert 200 characters with maxLength = -1. 36 PASS 37 Attempting to insert 200 characters with maxLength = 100. 38 PASS 39 Attempting to insert 200 characters with maxLength = 524288. 40 PASS 41 Attempting to insert 200 characters with maxLength = 600000. 42 PASS 43 Attempting to insert 524287 characters with maxLength = -1. 44 PASS 45 Attempting to insert 524287 characters with maxLength = 100. 46 PASS 47 Attempting to insert 524287 characters with maxLength = 524288. 48 PASS 49 Attempting to insert 524287 characters with maxLength = 600000. 50 PASS 51 Attempting to insert 524288 characters with maxLength = -1. 52 PASS 53 Attempting to insert 524288 characters with maxLength = 100. 54 PASS 55 Attempting to insert 524288 characters with maxLength = 524288. 56 PASS 57 Attempting to insert 524288 characters with maxLength = 600000. 58 PASS 59 Attempting to insert 524289 characters with maxLength = -1. 60 PASS 61 Attempting to insert 524289 characters with maxLength = 100. 62 PASS 63 Attempting to insert 524289 characters with maxLength = 524288. 64 PASS 65 Attempting to insert 524289 characters with maxLength = 600000. 66 PASS 67 Attempting to insert 530000 characters with maxLength = -1. 68 PASS 69 Attempting to insert 530000 characters with maxLength = 100. 70 PASS 71 Attempting to insert 530000 characters with maxLength = 524288. 72 PASS 73 Attempting to insert 530000 characters with maxLength = 600000. 74 PASS 75 PASS successfullyParsed is true 3 76 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 77 TEST COMPLETE 76 78 -
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> 1 7 <p>This page tests that the <tt>maxlength</tt> attribute of the <tt><input></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 2 10 <input id="input"> 3 <pre id="log"></pre> 11 4 12 <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; 13 14 var testString = ""; 14 15 var input = document.getElementById("input"); … … 16 17 function attempt(length, expected) 17 18 { 18 log("Attempting to insert " + length + " characters with maxLength = " + input.getAttribute("maxlength") + ".");19 debug("Attempting to insert " + length + " characters with maxLength = " + input.getAttribute("maxlength") + "."); 19 20 20 21 if (testString.length > length) … … 25 26 26 27 input.value = testString; 27 28 28 if (input.value.length == expected) 29 log("PASS");29 testPassed(""); 30 30 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."); 32 32 } 33 34 var implicitMaxLength = 524288;35 33 36 34 var stringLengthsToTest = [0, 5, 100, 101, 200, 524287, 524288, 524289, 530000]; … … 42 40 var maxLength = maxLengthsToTest[j]; 43 41 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); 47 43 attempt(stringLength, expected); 48 44 } 49 45 } 46 47 var successfullyParsed = true; 50 48 </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> 6 10 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̲̅45" maxlength="4"></td> 34 <td class="result">12x̲̅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̲̅45"></td> 38 <td class="result">12x̲̅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̲̅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̲̅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̲̅45"></td> 50 <td class="result">12x̲̅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̲̅45"></td> 54 <td class="result">12x̲̅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̲̅45" maxlength="4" id="input7"> 18 <input type="text" size="5" maxlength="4" value="12x̲̅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̲̅45"> 22 <input type="text" id="g" size="5" value="12x̲̅45"> 58 23 59 24 <script> 25 function domValueOf(id) { 26 return document.getElementById(id).value; 27 } 28 function visibleValueOf(id) { 29 var el = document.getElementById(id); 30 el.focus(); 31 document.execCommand('SelectAll'); 32 return document.getSelection().toString(); 33 } 34 60 35 var fancyX = "x" + String.fromCharCode(0x305) + String.fromCharCode(0x332); 36 37 debug('maxlength and value that violates it, maxlength first'); 38 shouldBe('domValueOf("input1")', '"12345"'); 39 shouldBe('visibleValueOf("input1")', '"12345"'); 40 41 debug('maxlength and value that violates it, maxlength first'); 42 shouldBe('domValueOf("input2")', '"12345"'); 43 shouldBe('visibleValueOf("input2")', '"12345"'); 44 45 debug('set value attribute that violates maxlength'); 46 document.getElementById("f").setAttribute('value', '12345'); 47 shouldBe('domValueOf("f")', '"12345"'); 48 shouldBe('visibleValueOf("input2")', '"12345"'); 49 50 debug('set value property that violates maxlength'); 51 document.getElementById("e").value = '12345'; 52 shouldBe('domValueOf("e")', '"12345"'); 53 shouldBe('visibleValueOf("e")', '"12345"'); 54 55 debug('set maxlength attribute that is smaller than initial value'); 56 document.getElementById("d").setAttribute('maxlength', 4); 57 shouldBe('domValueOf("d")', '"12345"'); 58 shouldBe('visibleValueOf("d")', '"12345"'); 59 60 debug('set maxLength property that is smaller than initial value'); 61 61 document.getElementById("c").maxLength = 4; 62 document.getElementById("d").setAttribute('maxlength', 4); 63 document.getElementById("e").value = '12345'; 64 document.getElementById("f").setAttribute('value', '12345'); 62 shouldBe('domValueOf("c")', '"12345"'); 63 shouldBe('visibleValueOf("c")', '"12345"'); 64 65 debug('maxlength and value that violates it, maxlength first'); 66 shouldBe('domValueOf("input7")', '"12" + fancyX + "45"'); 67 shouldBe('visibleValueOf("input7")', '"12" + fancyX + "45"'); 68 69 debug('maxlength and value that violates it, value first'); 70 shouldBe('domValueOf("input8")', '"12" + fancyX + "45"'); 71 shouldBe('visibleValueOf("input8")', '"12" + fancyX + "45"'); 72 73 debug('set value attribute that violates maxlength'); 74 document.getElementById("j").setAttribute('value', '12' + fancyX + '45'); 75 shouldBe('domValueOf("j")', '"12" + fancyX + "45"'); 76 shouldBe('visibleValueOf("j")', '"12" + fancyX + "45"'); 77 78 debug('set value property that violates maxlength'); 79 document.getElementById("i").value = '12' + fancyX + '45'; 80 shouldBe('domValueOf("i")', '"12" + fancyX + "45"'); 81 shouldBe('visibleValueOf("i")', '"12" + fancyX + "45"'); 82 83 debug('set maxlength attribute that is smaller than initial value'); 84 document.getElementById("h").setAttribute('maxlength', 4); 85 shouldBe('domValueOf("h")', '"12" + fancyX + "45"'); 86 shouldBe('visibleValueOf("h")', '"12" + fancyX + "45"'); 87 88 debug('set maxLength property that is smaller than initial value'); 65 89 document.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'); 90 shouldBe('domValueOf("g")', '"12" + fancyX + "45"'); 91 shouldBe('visibleValueOf("g")', '"12" + fancyX + "45"'); 92 93 var successfullyParsed = true; 69 94 </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> 6 10 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̲̅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̲̅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̲̅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̲̅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"> 46 20 47 21 <script> 22 function domValueOf(id) { 23 return document.getElementById(id).value; 24 } 25 function visibleValueOf(id) { 26 var el = document.getElementById(id); 27 el.focus(); 28 document.execCommand('SelectAll'); 29 return document.getSelection().toString(); 30 } 31 48 32 var fancyX = "x" + String.fromCharCode(0x305) + String.fromCharCode(0x332); 33 34 debug("set value attribute that violates maxlength (with pasted value)"); 35 document.getElementById("f").focus(); 36 document.execCommand("InsertHTML", false, "123"); 37 document.getElementById("f").setAttribute('value', '12345'); 38 shouldBe("domValueOf('f')", "'123'"); // setAttribute() doesn't change the value because the value is dirty. 39 shouldBe("visibleValueOf('f')", "'123'"); 40 41 debug("set value property that violates maxlength (with pasted value)"); 42 document.getElementById("e").focus(); 43 document.execCommand("InsertHTML", false, "123"); 44 document.getElementById("e").value = '12345'; 45 shouldBe("domValueOf('e')", "'12345'"); // Unlike setAttribute(), .value property changes the value. 46 shouldBe("visibleValueOf('e')", "'12345'"); 47 48 debug("set maxlength attribute that is smaller than pasted value"); 49 document.getElementById("d").focus(); 50 document.execCommand("InsertHTML", false, "12345"); 51 document.getElementById("d").setAttribute('maxlength', 4); 52 shouldBe("domValueOf('d')", "'12345'"); 53 shouldBe("visibleValueOf('d')", "'12345'"); 54 55 debug("set maxLength property that is smaller than pasted value"); 49 56 document.getElementById("c").focus(); 50 57 document.execCommand("InsertHTML", false, "12345"); 51 58 document.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(); 59 shouldBe("domValueOf('c')", "'12345'"); 60 shouldBe("visibleValueOf('c')", "'12345'"); 61 62 debug("set value attribute that violates maxlength (with pasted value)"); 63 document.getElementById("j").focus(); 56 64 document.execCommand("InsertHTML", false, "123"); 57 document.getElementById("e").value = '12345'; 58 document.getElementById("f").focus(); 65 document.getElementById("j").setAttribute('value', '12' + fancyX + '45'); 66 shouldBe("domValueOf('j')", "'123'"); 67 shouldBe("visibleValueOf('j')", "'123'"); 68 69 debug("set value property that violates maxlength (with pasted value)"); 70 document.getElementById("i").focus(); 59 71 document.execCommand("InsertHTML", false, "123"); 60 document.getElementById("f").setAttribute('value', '12345'); 72 document.getElementById("i").value = '12' + fancyX + '45'; 73 shouldBe("domValueOf('i')", "'12' + fancyX + '45'"); 74 shouldBe("visibleValueOf('i')", "'12' + fancyX + '45'"); 75 76 debug("set maxlength attribute that is smaller than pasted value"); 77 document.getElementById("h").focus(); 78 document.execCommand("InsertHTML", false, "12x̲̅45"); 79 document.getElementById("h").setAttribute('maxlength', 4); 80 shouldBe("domValueOf('h')", "'12' + fancyX + '45'"); 81 shouldBe("visibleValueOf('h')", "'12' + fancyX + '45'"); 82 83 debug("set maxLength property that is smaller than pasted value"); 61 84 document.getElementById("g").focus(); 62 85 document.execCommand("InsertHTML", false, "12x̲̅45"); 63 86 document.getElementById("g").maxLength = 4; 64 document.getElementById("h").focus(); 65 document.execCommand("InsertHTML", false, "12x̲̅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'); 87 shouldBe("domValueOf('g')", "'12' + fancyX + '45'"); 88 shouldBe("visibleValueOf('g')", "'12' + fancyX + '45'"); 89 90 debug("pasting too much text"); 73 91 document.getElementById("k").focus(); 74 92 document.execCommand("InsertHTML", false, "12x̲̅45"); 75 document.getElementById("k").blur(); 93 shouldBe("domValueOf('k')", "'12' + fancyX + '4'"); 94 shouldBe("visibleValueOf('k')", "'12' + fancyX + '4'"); 95 96 var successfullyParsed = true; 76 97 </script> 98 <script src="../../fast/js/resources/js-test-post.js"></script> 99 </body> 100 </html> -
trunk/WebCore/ChangeLog
r48448 r48449 1 2009-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 1 28 2009-09-16 Enrica Casucci <enrica@apple.com> 2 29 -
trunk/WebCore/dom/InputElement.cpp
r48011 r48449 47 47 48 48 // 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 things49 // large. However, due to https://bugs.webkit.org/show_bug.cgi?id=14536 things 50 50 // get rather sluggish when a text field has a larger number of characters than 51 51 // this, even when just clicking in the text field. … … 139 139 void InputElement::setValueFromRenderer(InputElementData& data, InputElement* inputElement, Element* element, const String& value) 140 140 { 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()); 143 143 144 144 if (inputElement->isTextField()) … … 177 177 } 178 178 179 String InputElement::constrainValue(const InputElement* inputElement, const String& proposedValue, int maxLength) 180 { 179 String InputElement::sanitizeValue(const InputElement* inputElement, const String& proposedValue) 180 { 181 return InputElement::sanitizeUserInputValue(inputElement, proposedValue, s_maximumLength); 182 } 183 184 String InputElement::sanitizeUserInputValue(const InputElement* inputElement, const String& proposedValue, int maxLength) 185 { 186 if (!inputElement->isTextField()) 187 return proposedValue; 188 181 189 String string = proposedValue; 182 if (!inputElement->isTextField())183 return string;184 185 190 string.replace("\r\n", " "); 186 191 string.replace('\r', ' '); 187 192 string.replace('\n', ' '); 188 193 189 194 StringImpl* s = string.impl(); 190 195 int newLength = numCharactersInGraphemeClusters(s, maxLength); … … 225 230 226 231 // We use RenderTextControlSingleLine::text() instead of InputElement::value() 227 // because they can be mismatched by constrainValue() in228 // RenderTextControlSingleLine::subtreeHasChanged() in a case of IME input.232 // because they can be mismatched by sanitizeValue() in 233 // RenderTextControlSingleLine::subtreeHasChanged() in some cases. 229 234 int oldLength = numGraphemeClusters(toRenderTextControlSingleLine(element->renderer())->text().impl()); 230 235 … … 239 244 // Truncate the inserted text to avoid violating the maxLength and other constraints. 240 245 BeforeTextInsertedEvent* textEvent = static_cast<BeforeTextInsertedEvent*>(event); 241 textEvent->setText( constrainValue(inputElement, textEvent->text(), appendableLength));246 textEvent->setText(sanitizeUserInputValue(inputElement, textEvent->text(), appendableLength)); 242 247 } 243 248 … … 268 273 { 269 274 String oldValue = data.value(); 270 String newValue = inputElement->constrainValue(oldValue);275 String newValue = sanitizeValue(inputElement, oldValue); 271 276 if (newValue != oldValue) 272 277 inputElement->setValue(newValue); -
trunk/WebCore/dom/InputElement.h
r48011 r48449 55 55 virtual void setPlaceholder(const String&) = 0; 56 56 57 virtual String constrainValue(const String&) const = 0;57 virtual String sanitizeValue(const String&) const = 0; 58 58 virtual void setValueFromRenderer(const String&) = 0; 59 59 … … 73 73 static void aboutToUnload(InputElement*, Element*); 74 74 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); 76 81 static void handleBeforeTextInsertedEvent(InputElementData&, InputElement*, Element*, Event*); 77 82 static void parseSizeAttribute(InputElementData&, Element*, MappedAttribute*); -
trunk/WebCore/html/HTMLInputElement.cpp
r48244 r48449 355 355 } 356 356 if (!didStoreValue && willStoreValue) 357 m_data.setValue( constrainValue(getAttribute(valueAttr)));357 m_data.setValue(sanitizeValue(getAttribute(valueAttr))); 358 358 else 359 359 InputElement::updateValueIfNeeded(m_data, this); … … 1054 1054 String value = m_data.value(); 1055 1055 if (value.isNull()) { 1056 value = constrainValue(getAttribute(valueAttr));1056 value = sanitizeValue(getAttribute(valueAttr)); 1057 1057 1058 1058 // If no attribute exists, then just use "on" or "" based off the checked() state of the control. … … 1110 1110 m_fileList->clear(); 1111 1111 else { 1112 m_data.setValue( constrainValue(value));1112 m_data.setValue(sanitizeValue(value)); 1113 1113 if (isTextField()) { 1114 1114 InputElement::updatePlaceholderVisibility(this, this); … … 1121 1121 setNeedsStyleRecalc(); 1122 1122 } else 1123 setAttribute(valueAttr, constrainValue(value));1123 setAttribute(valueAttr, sanitizeValue(value)); 1124 1124 1125 1125 if (isTextField()) { … … 1669 1669 } 1670 1670 1671 String HTMLInputElement::constrainValue(const String& proposedValue) const 1672 { 1673 return InputElement::constrainValue(this, proposedValue, m_data.maxLength()); 1671 String HTMLInputElement::sanitizeValue(const String& proposedValue) const 1672 { 1673 if (isTextField()) 1674 return InputElement::sanitizeValue(this, proposedValue); 1675 return proposedValue; 1674 1676 } 1675 1677 -
trunk/WebCore/html/HTMLInputElement.h
r48163 r48449 223 223 VisibleSelection selection() const; 224 224 225 virtual String constrainValue(const String& proposedValue) const;225 virtual String sanitizeValue(const String&) const; 226 226 227 227 virtual void documentDidBecomeActive(); -
trunk/WebCore/rendering/RenderTextControlSingleLine.cpp
r48370 r48449 156 156 157 157 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())); 159 163 160 164 if (m_cancelButton) -
trunk/WebCore/wml/WMLInputElement.cpp
r48011 r48449 310 310 String WMLInputElement::constrainValue(const String& proposedValue) const 311 311 { 312 return InputElement:: constrainValue(this, proposedValue, m_data.maxLength());312 return InputElement::sanitizeUserInputValue(this, proposedValue, m_data.maxLength()); 313 313 } 314 314 -
trunk/WebCore/wml/WMLInputElement.h
r44480 r48449 80 80 virtual void cacheSelection(int start, int end); 81 81 82 virtual String constrainValue(const String& proposedValue) const;82 virtual String sanitizeValue(const String& proposedValue) const { return constrainValue(proposedValue); } 83 83 84 84 virtual void documentDidBecomeActive(); … … 97 97 String validateInputMask(const String&); 98 98 unsigned cursorPositionToMaskIndex(unsigned); 99 String constrainValue(const String&) const; 99 100 100 101 InputElementData m_data;
Note: See TracChangeset
for help on using the changeset viewer.