Commit e2353175 authored by eric@webkit.org's avatar eric@webkit.org

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):

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@48449 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 0772608c
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-16 Geoffrey Garen <ggaren@apple.com>
Reviewed by Sam Weinig.
......
This test changes the value of the text field by simulating typing, and then gets the value.
This test changes the value of the text field by simulating typing, and then gets the value.
On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
PASS Maxlength shouldn't work for default value.
PASS Maxlength works for inserted text.
PASS successfullyParsed is true
TEST COMPLETE
Test 1 Passed. Maxlength works for default value. Test 2 Passed. Maxlength works for inserted text.
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../fast/js/resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<input type="text" id="sp" style="-khtml-appearance:textfield" maxlength=5 value="123456"></input>
<script>
description('This test changes the value of the text field by simulating typing, and then gets the value.');
function test()
{
var res = "";
if (window.layoutTestController) {
layoutTestController.dumpAsText();
}
if (document.getElementById('sp').value == "12345") {
res+= "Test 1 Passed. Maxlength works for default value.\n";
} else {
res+= "Test 1 Failed. Maxlength does not work for default value.\n";
}
document.getElementById('sp').value = "123";
document.getElementById('sp').setSelectionRange(0, 3);
document.getElementById('sp').focus();
document.execCommand("InsertText", false, 'abcd');
document.execCommand("InsertText", false, 'efghi');
var input = document.getElementById('sp');
if (input.value != "12345") {
testPassed('Maxlength shouldn\'t work for default value.\n');
} else {
testFailed('Maxlength unexpectedly works for default value.\n');
}
if (document.getElementById('sp').value == "abcde") {
res+= "Test 2 Passed. Maxlength works for inserted text.\n";
} else {
res+= "Test 2 Failed. Maxlength does not work for inserted text.\n";
}
input.value = "123";
input.setSelectionRange(0, 3);
input.focus();
document.execCommand("InsertText", false, 'abcd');
document.execCommand("InsertText", false, 'efghi');
document.getElementById('result').innerHTML = res;
if (input.value == "abcde") {
testPassed('Maxlength works for inserted text.\n');
} else {
testFailed('Maxlength does not work for inserted text.\n');
}
var successfullyParsed = true;
</script>
</head>
<body onload="test()">
This test changes the value of the text field by simulating typing, and then gets the value.
<br><br>
<input type="text" id="sp" style="-khtml-appearance:textfield" maxlength=5 value="123456"></input>
<div id="result">
</div>
<script src="../../fast/js/resources/js-test-post.js"></script>
</body>
</html>
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
PASS
Attempting to insert 0 characters with maxLength = 100.
PASS
PASS
Attempting to insert 0 characters with maxLength = 524288.
PASS
PASS
Attempting to insert 0 characters with maxLength = 600000.
PASS
PASS
Attempting to insert 5 characters with maxLength = -1.
PASS
PASS
Attempting to insert 5 characters with maxLength = 100.
PASS
PASS
Attempting to insert 5 characters with maxLength = 524288.
PASS
PASS
Attempting to insert 5 characters with maxLength = 600000.
PASS
PASS
Attempting to insert 100 characters with maxLength = -1.
PASS
PASS
Attempting to insert 100 characters with maxLength = 100.
PASS
PASS
Attempting to insert 100 characters with maxLength = 524288.
PASS
PASS
Attempting to insert 100 characters with maxLength = 600000.
PASS
PASS
Attempting to insert 101 characters with maxLength = -1.
PASS
PASS
Attempting to insert 101 characters with maxLength = 100.
PASS
PASS
Attempting to insert 101 characters with maxLength = 524288.
PASS
PASS
Attempting to insert 101 characters with maxLength = 600000.
PASS
PASS
Attempting to insert 200 characters with maxLength = -1.
PASS
PASS
Attempting to insert 200 characters with maxLength = 100.
PASS
PASS
Attempting to insert 200 characters with maxLength = 524288.
PASS
PASS
Attempting to insert 200 characters with maxLength = 600000.
PASS
PASS
Attempting to insert 524287 characters with maxLength = -1.
PASS
PASS
Attempting to insert 524287 characters with maxLength = 100.
PASS
PASS
Attempting to insert 524287 characters with maxLength = 524288.
PASS
PASS
Attempting to insert 524287 characters with maxLength = 600000.
PASS
PASS
Attempting to insert 524288 characters with maxLength = -1.
PASS
PASS
Attempting to insert 524288 characters with maxLength = 100.
PASS
PASS
Attempting to insert 524288 characters with maxLength = 524288.
PASS
PASS
Attempting to insert 524288 characters with maxLength = 600000.
PASS
PASS
Attempting to insert 524289 characters with maxLength = -1.
PASS
PASS
Attempting to insert 524289 characters with maxLength = 100.
PASS
PASS
Attempting to insert 524289 characters with maxLength = 524288.
PASS
PASS
Attempting to insert 524289 characters with maxLength = 600000.
PASS
PASS
Attempting to insert 530000 characters with maxLength = -1.
PASS
PASS
Attempting to insert 530000 characters with maxLength = 100.
PASS
PASS
Attempting to insert 530000 characters with maxLength = 524288.
PASS
PASS
Attempting to insert 530000 characters with maxLength = 600000.
PASS
PASS
PASS successfullyParsed is true
TEST COMPLETE
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../fast/js/resources/js-test-pre.js"></script>
</head>
<body>
<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"));
}
<div id="console"></div>
if (window.layoutTestController)
layoutTestController.dumpAsText();
<input id="input">
<script>
var implicitMaxLength = 524288;
var testString = "";
var input = document.getElementById("input");
function attempt(length, expected)
{
log("Attempting to insert " + length + " characters with maxLength = " + input.getAttribute("maxlength") + ".");
debug("Attempting to insert " + length + " characters with maxLength = " + input.getAttribute("maxlength") + ".");
if (testString.length > length)
testString = "";
......@@ -24,15 +25,12 @@
testString += i % 10;
input.value = testString;
if (input.value.length == expected)
log("PASS");
testPassed("");
else
log("FAIL: Expected " + expected + " characters to be inserted, but " + input.value.length + " characters were actually inserted.");
testFailed("Expected " + domExpected + " 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"];
......@@ -41,10 +39,13 @@
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);
var expected = Math.min(stringLength, implicitMaxLength);
attempt(stringLength, expected);
}
}
var successfullyParsed = true;
</script>
<script src="../../fast/js/resources/js-test-post.js"></script>
</body>
</html>
maxlength and value that violates it, maxlength first
PASS domValueOf("input1") is "12345"
PASS visibleValueOf("input1") is "12345"
maxlength and value that violates it, maxlength first
PASS domValueOf("input2") is "12345"
PASS visibleValueOf("input2") is "12345"
set value attribute that violates maxlength
PASS domValueOf("f") is "12345"
PASS visibleValueOf("input2") is "12345"
set value property that violates maxlength
PASS domValueOf("e") is "12345"
PASS visibleValueOf("e") is "12345"
set maxlength attribute that is smaller than initial value
PASS domValueOf("d") is "12345"
PASS visibleValueOf("d") is "12345"
set maxLength property that is smaller than initial value
PASS domValueOf("c") is "12345"
PASS visibleValueOf("c") is "12345"
maxlength and value that violates it, maxlength first
PASS domValueOf("input7") is "12" + fancyX + "45"
PASS visibleValueOf("input7") is "12" + fancyX + "45"
maxlength and value that violates it, value first
PASS domValueOf("input8") is "12" + fancyX + "45"
PASS visibleValueOf("input8") is "12" + fancyX + "45"
set value attribute that violates maxlength
PASS domValueOf("j") is "12" + fancyX + "45"
PASS visibleValueOf("j") is "12" + fancyX + "45"
set value property that violates maxlength
PASS domValueOf("i") is "12" + fancyX + "45"
PASS visibleValueOf("i") is "12" + fancyX + "45"
set maxlength attribute that is smaller than initial value
PASS domValueOf("h") is "12" + fancyX + "45"
PASS visibleValueOf("h") is "12" + fancyX + "45"
set maxLength property that is smaller than initial value
PASS domValueOf("g") is "12" + fancyX + "45"
PASS visibleValueOf("g") is "12" + fancyX + "45"
PASS successfullyParsed is true
TEST COMPLETE
<style>
table { font: 11px 'Lucida Grande' }
.result { color: GrayText; padding-left: 4px; padding-right: 8px }
.result:before { content: "expected: " }
</style>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
<script src="../../fast/js/resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<table>
<input type="text" size="5" value="12345" maxlength="4" id="input1">
<input type="text" size="5" maxlength="4" value="12345" id="input2">
<input type="text" id="f" size="5" maxlength="4" value="123">
<input type="text" id="e" size="5" maxlength="4" value="123">
<input type="text" id="d" size="5" value="12345">
<input type="text" id="c" size="5" value="12345">
<input type="text" size="5" value="12x&#x305;&#x332;45" maxlength="4" id="input7">
<input type="text" size="5" maxlength="4" value="12x&#x305;&#x332;45" id="input8">
<input type="text" id="j" size="5" maxlength="4" value="123">
<input type="text" id="i" size="5" maxlength="4" value="123">
<input type="text" id="h" size="5" value="12x&#x305;&#x332;45">
<input type="text" id="g" size="5" value="12x&#x305;&#x332;45">
<tr><td><input type="text" size="5" value="12345" maxlength="4"></td>
<td class="result">1234</td>
<td class="description">maxlength and value that violates it, maxlength first</td></tr>
<script>
function domValueOf(id) {
return document.getElementById(id).value;
}
function visibleValueOf(id) {
var el = document.getElementById(id);
el.focus();
document.execCommand('SelectAll');
return document.getSelection().toString();
}
<tr><td><input type="text" size="5" maxlength="4" value="12345"></td>
<td class="result">1234</td>
<td class="description">maxlength and value that violates it, value first</td></tr>
var fancyX = "x" + String.fromCharCode(0x305) + String.fromCharCode(0x332);
<tr><td><input type="text" id="f" size="5" maxlength="4" value="123"></td>
<td class="result">1234</td>
<td class="description">set value attribute that violates maxlength</td></tr>
debug('maxlength and value that violates it, maxlength first');
shouldBe('domValueOf("input1")', '"12345"');
shouldBe('visibleValueOf("input1")', '"12345"');
<tr><td><input type="text" id="e" size="5" maxlength="4" value="123"></td>
<td class="result">1234</td>
<td class="description">set value property that violates maxlength</td></tr>
debug('maxlength and value that violates it, maxlength first');
shouldBe('domValueOf("input2")', '"12345"');
shouldBe('visibleValueOf("input2")', '"12345"');
<tr><td><input type="text" id="d" size="5" value="12345"></td>
<td class="result">1234</td>
<td class="description">set maxlength attribute that is smaller than initial value</td></tr>
debug('set value attribute that violates maxlength');
document.getElementById("f").setAttribute('value', '12345');
shouldBe('domValueOf("f")', '"12345"');
shouldBe('visibleValueOf("input2")', '"12345"');
<tr><td><input type="text" id="c" size="5" value="12345"></td>
<td class="result">1234</td>
<td class="description">set maxLength property that is smaller than initial value</td></tr>
debug('set value property that violates maxlength');
document.getElementById("e").value = '12345';
shouldBe('domValueOf("e")', '"12345"');
shouldBe('visibleValueOf("e")', '"12345"');
<tr><td><input type="text" size="5" value="12x&#x305;&#x332;45" maxlength="4"></td>
<td class="result">12x&#x305;&#x332;4</td>
<td class="description">maxlength and value that violates it, maxlength first</td></tr>
debug('set maxlength attribute that is smaller than initial value');
document.getElementById("d").setAttribute('maxlength', 4);
shouldBe('domValueOf("d")', '"12345"');
shouldBe('visibleValueOf("d")', '"12345"');
<tr><td><input type="text" size="5" maxlength="4" value="12x&#x305;&#x332;45"></td>
<td class="result">12x&#x305;&#x332;4</td>
<td class="description">maxlength and value that violates it, value first</td></tr>
debug('set maxLength property that is smaller than initial value');
document.getElementById("c").maxLength = 4;
shouldBe('domValueOf("c")', '"12345"');
shouldBe('visibleValueOf("c")', '"12345"');
<tr><td><input type="text" id="j" size="5" maxlength="4" value="123"></td>
<td class="result">12x&#x305;&#x332;4</td>
<td class="description">set value attribute that violates maxlength</td></tr>
debug('maxlength and value that violates it, maxlength first');
shouldBe('domValueOf("input7")', '"12" + fancyX + "45"');
shouldBe('visibleValueOf("input7")', '"12" + fancyX + "45"');
<tr><td><input type="text" id="i" size="5" maxlength="4" value="123"></td>
<td class="result">12x&#x305;&#x332;4</td>
<td class="description">set value property that violates maxlength</td></tr>
debug('maxlength and value that violates it, value first');
shouldBe('domValueOf("input8")', '"12" + fancyX + "45"');
shouldBe('visibleValueOf("input8")', '"12" + fancyX + "45"');
<tr><td><input type="text" id="h" size="5" value="12x&#x305;&#x332;45"></td>
<td class="result">12x&#x305;&#x332;4</td>
<td class="description">set maxlength attribute that is smaller than initial value</td></tr>
debug('set value attribute that violates maxlength');
document.getElementById("j").setAttribute('value', '12' + fancyX + '45');
shouldBe('domValueOf("j")', '"12" + fancyX + "45"');
shouldBe('visibleValueOf("j")', '"12" + fancyX + "45"');
<tr><td><input type="text" id="g" size="5" value="12x&#x305;&#x332;45"></td>
<td class="result">12x&#x305;&#x332;4</td>
<td class="description">set maxLength property that is smaller than initial value</td></tr>
debug('set value property that violates maxlength');
document.getElementById("i").value = '12' + fancyX + '45';
shouldBe('domValueOf("i")', '"12" + fancyX + "45"');
shouldBe('visibleValueOf("i")', '"12" + fancyX + "45"');
</table>
debug('set maxlength attribute that is smaller than initial value');
document.getElementById("h").setAttribute('maxlength', 4);
shouldBe('domValueOf("h")', '"12" + fancyX + "45"');
shouldBe('visibleValueOf("h")', '"12" + fancyX + "45"');
<script>
var fancyX = "x" + String.fromCharCode(0x305) + String.fromCharCode(0x332);
document.getElementById("c").maxLength = 4;
document.getElementById("d").setAttribute('maxlength', 4);
document.getElementById("e").value = '12345';
document.getElementById("f").setAttribute('value', '12345');
debug('set maxLength property that is smaller than initial value');
document.getElementById("g").maxLength = 4;
document.getElementById("h").setAttribute('maxlength', 4);
document.getElementById("i").value = '12' + fancyX + '45';
document.getElementById("j").setAttribute('value', '12' + fancyX + '45');
shouldBe('domValueOf("g")', '"12" + fancyX + "45"');
shouldBe('visibleValueOf("g")', '"12" + fancyX + "45"');
var successfullyParsed = true;
</script>
<script src="../../fast/js/resources/js-test-post.js"></script>
</body>
</html>
set value attribute that violates maxlength (with pasted value)
PASS domValueOf('f') is '123'
PASS visibleValueOf('f') is '123'
set value property that violates maxlength (with pasted value)
PASS domValueOf('e') is '12345'
PASS visibleValueOf('e') is '12345'
set maxlength attribute that is smaller than pasted value
PASS domValueOf('d') is '12345'
PASS visibleValueOf('d') is '12345'
set maxLength property that is smaller than pasted value
PASS domValueOf('c') is '12345'
PASS visibleValueOf('c') is '12345'
set value attribute that violates maxlength (with pasted value)
PASS domValueOf('j') is '123'
PASS visibleValueOf('j') is '123'
set value property that violates maxlength (with pasted value)
PASS domValueOf('i') is '12' + fancyX + '45'
PASS visibleValueOf('i') is '12' + fancyX + '45'
set maxlength attribute that is smaller than pasted value
PASS domValueOf('h') is '12' + fancyX + '45'
PASS visibleValueOf('h') is '12' + fancyX + '45'
set maxLength property that is smaller than pasted value
PASS domValueOf('g') is '12' + fancyX + '45'
PASS visibleValueOf('g') is '12' + fancyX + '45'
pasting too much text
PASS domValueOf('k') is '12' + fancyX + '4'
PASS visibleValueOf('k') is '12' + fancyX + '4'
PASS successfullyParsed is true
TEST COMPLETE
<style>
table { font: 11px 'Lucida Grande' }
.result { color: GrayText; padding-left: 4px; padding-right: 8px }
.result:before { content: "expected: " }
</style>
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<link rel="stylesheet" href="../../fast/js/resources/js-test-style.css">
<script src="../../fast/js/resources/js-test-pre.js"></script>
</head>
<body>
<p id="description"></p>
<div id="console"></div>
<table>
<input type="text" id="f" size="5" maxlength="4">
<input type="text" id="e" size="5" maxlength="4">
<input type="text" id="d" size="5">
<input type="text" id="c" size="5">
<input type="text" id="j" size="5" maxlength="4">
<input type="text" id="i" size="5" maxlength="4">
<input type="text" id="h" size="5">
<input type="text" id="g" size="5">
<input type="text" id="k" size="5" maxlength="4">
<tr><td><input type="text" id="f" size="5" maxlength="4"></td>
<td class="result">123</td>
<td class="description">set value attribute that violates maxlength (with pasted value)</td></tr>
<tr><td><input type="text" id="e" size="5" maxlength="4"></td>
<td class="result">1234</td>
<td class="description">set value property that violates maxlength (with pasted value)</td></tr>
<tr><td><input type="text" id="d" size="5"></td>
<td class="result">1234</td>
<td class="description">set maxlength attribute that is smaller than pasted value</td></tr>
<tr><td><input type="text" id="c" size="5"></td>
<td class="result">1234</td>
<td class="description">set maxLength property that is smaller than pasted value</td></tr>
<tr><td><input type="text" id="j" size="5" maxlength="4"></td>
<td class="result">123</td>
<td class="description">set value attribute that violates maxlength (with pasted value)</td></tr>
<tr><td><input type="text" id="i" size="5" maxlength="4"></td>
<td class="result">12x&#x305;&#x332;4</td>
<td class="description">set value property that violates maxlength (with pasted value)</td></tr>
<script>
function domValueOf(id) {
return document.getElementById(id).value;
}
function visibleValueOf(id) {
var el = document.getElementById(id);
el.focus();
document.execCommand('SelectAll');
return document.getSelection().toString();
}
<tr><td><input type="text" id="h" size="5"></td>
<td class="result">12x&#x305;&#x332;4</td>
<td class="description">set maxlength attribute that is smaller than pasted value</td></tr>
var fancyX = "x" + String.fromCharCode(0x305) + String.fromCharCode(0x332);
<tr><td><input type="text" id="g" size="5"></td>
<td class="result">12x&#x305;&#x332;4</td>
<td class="description">set maxLength property that is smaller than pasted value</td></tr>
debug("set value attribute that violates maxlength (with pasted value)");
document.getElementById("f").focus();
document.execCommand("InsertHTML", false, "123");
document.getElementById("f").setAttribute('value', '12345');
shouldBe("domValueOf('f')", "'123'"); // setAttribute() doesn't change the value because the value is dirty.
shouldBe("visibleValueOf('f')", "'123'");