Properly serialize form fields with names that collide with built-in JS properties (like "length" or "toString"). Closes #9609. [gryn, kangax]

This commit is contained in:
Andrew Dupont 2008-01-24 02:24:33 +00:00
parent 17cd2f9f8d
commit 0f97f4ce20
3 changed files with 13 additions and 1 deletions

View File

@ -1,5 +1,7 @@
*SVN*
* Properly serialize form fields with names that collide with built-in JS properties (like "length" or "toString"). Closes #9609. [gryn, kangax]
* Make Object.isArray correctly identify arrays created in another frame. Closes #10374. [pointy, Dean Edwards, Andrew Dupont, Tobie Langel]
* Fixed issue where Element#match failed on attribute selectors with single or double quotes. Closes #10067. [Cezary Okupski, Andrew Dupont]

View File

@ -14,7 +14,7 @@ var Form = {
key = element.name; value = $(element).getValue();
if (value != null && (element.type != 'submit' || (!submitted &&
submit !== false && (!submit || key == submit) && (submitted = true)))) {
if (key in result) {
if (key in result && !Object.isFunction(result[key])) {
// a key is already present; construct an array of values
if (!Object.isArray(result[key])) result[key] = [result[key]];
result[key].push(value);

View File

@ -124,6 +124,12 @@
<input type="checkbox" id="ffe_ti2_checkbox" tabindex="0" />
<input type="submit" id="ffe_ti2_submit" tabindex="1" />
</form>
<form id="trouble_form">
<input type="text" name="length" value="foo" />
<input type="text" name="toString" value="55" />
<input type="text" name="valueOf" value="bar" />
</form>
</div>
<!-- Tests follow -->
@ -400,6 +406,10 @@
$('form').serialize({ submit: false }));
assertHashEqual({ val1:4, action:'blah' },
$('form').serialize({ submit: 'inexistent' }));
// try to serialize form containing toString, valueOf and length -named elements
assertHashEqual({ length: 'foo', toString: 55, valueOf: 'bar' },
$('trouble_form').serialize(true));
}},
testFormMethodsOnExtendedElements: function() {with(this) {