Bug 260908 - Trim leading & trailing whitespace on new form history entries. r=dolske

This commit is contained in:
Matt Noorenberghe 2009-06-10 16:32:39 -07:00
Родитель 5cb3a6b2e8
Коммит 4d34a8978f
2 изменённых файлов: 33 добавлений и 4 удалений

Просмотреть файл

@ -509,6 +509,7 @@ nsFormHistory::Notify(nsIDOMHTMLFormElement* formElt, nsIDOMWindowInternal* aWin
// If this input has a name/id and value, add it to the database
nsAutoString value;
inputElt->GetValue(value);
value.Trim(" \t", PR_TRUE, PR_TRUE);
if (!value.IsEmpty()) {
// Ignore the input if the value hasn't been changed from the
// default. We only want to save data entered by the user.

Просмотреть файл

@ -78,6 +78,12 @@
<button type="submit">Submit</button>
</form>
<!-- input with value of one space (which should be trimmed) -->
<form id="form12" onsubmit="return checkSubmit(12)">
<input type="text" name="test1">
<button type="submit">Submit</button>
</form>
<!-- ===== Things that should be saved ===== -->
@ -99,6 +105,18 @@
<button type="submit">Submit</button>
</form>
<!-- input with leading and trailing space -->
<form id="form104" onsubmit="return checkSubmit(104)">
<input type="text" name="test4">
<button type="submit">Submit</button>
</form>
<!-- input with leading and trailing whitespace -->
<form id="form105" onsubmit="return checkSubmit(105)">
<input type="text" name="test5">
<button type="submit">Submit</button>
</form>
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
@ -126,10 +144,13 @@ function startTest() {
// Form 9 has nothing to modify.
$_(10, "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890").value = "dontSaveThis";
$_(11, "test1").value = "12345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890";
$_(12, "test1").value = " ";
$_(101, "test1").value = "savedValue";
$_(102, "test2").value = "savedValue";
$_(103, "test3").value = "savedValue";
$_(104, "test4").value = " trimTrailingAndLeadingSpace ";
$_(105, "test5").value = "\t trimTrailingAndLeadingWhitespace\t ";
// submit the first form.
var button = getFormSubmitButton(1);
@ -147,7 +168,7 @@ function checkSubmit(formNum) {
// Check for expected storage state.
switch (formNum) {
// Test 1-9 should not save anything.
// Test 1-12 should not save anything.
case 1:
case 2:
case 3:
@ -159,6 +180,7 @@ function checkSubmit(formNum) {
case 9:
case 10:
case 11:
case 12:
ok(!fh.hasEntries, "checking for empty storage");
break;
// The other tests do save data...
@ -171,20 +193,26 @@ function checkSubmit(formNum) {
case 103:
ok(fh.entryExists("test3", "savedValue"), "checking saved value");
break;
case 104:
ok(fh.entryExists("test4", "trimTrailingAndLeadingSpace"), "checking saved value is trimmed on both sides");
break;
case 105:
ok(fh.entryExists("test5", "trimTrailingAndLeadingWhitespace"), "checking saved value is trimmed on both sides");
break;
default:
ok(false, "Unexpected form submission");
break;
}
// End the test at the last form.
if (formNum == 103) {
is(numSubmittedForms, 14, "Ensuring all forms were submitted.");
if (formNum == 105) {
is(numSubmittedForms, 17, "Ensuring all forms were submitted.");
SimpleTest.finish();
return false; // return false to cancel current form submission
}
// submit the next form.
var button = getFormSubmitButton(formNum == 11 ? 101 : (formNum + 1));
var button = getFormSubmitButton(formNum == 12 ? 101 : (formNum + 1));
button.click();
return false; // cancel current form submission