aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortimmywil <tim.willison@thisismedium.com>2011-03-25 00:35:50 -0400
committertimmywil <tim.willison@thisismedium.com>2011-04-03 19:13:39 -0400
commit102053abd84124b1a69606565bd8da82bc5d30e9 (patch)
tree774240cc9446a8e735507fa43e5e036d7fd2f5ba
parent11cfdb23940b2c76e1104c82afc9552ac6f3dc19 (diff)
downloadjquery-102053abd84124b1a69606565bd8da82bc5d30e9.tar.gz
jquery-102053abd84124b1a69606565bd8da82bc5d30e9.zip
Fix #7472 and added test for #3113
- Forms with an input that has either name="action" or name="some-other-attr-on-the-form" caused problems in IE6/7. This is fixed. - Changed check in $.attr for ret === null to typeof ret === "object" to catch any inputs that are accidentally retrieved in IE6/7, since attributes cannot be set to objects and typeof null === "object"
-rw-r--r--src/attributes.js3
-rw-r--r--test/index.html1
-rw-r--r--test/unit/attributes.js8
3 files changed, 8 insertions, 4 deletions
diff --git a/src/attributes.js b/src/attributes.js
index dc9a333bb..564eaeeb8 100644
--- a/src/attributes.js
+++ b/src/attributes.js
@@ -320,7 +320,8 @@ jQuery.extend({
ret = elem.getAttribute( name );
// Non-existent attributes return null, we normalize to undefined
- return ret === null || ret === "null" ?
+ // Instead of checking for null, we check for typeof object to catch inputs in IE6/7. Bug #7472
+ return typeof ret === "object" || ret === "null" ?
undefined :
ret;
}
diff --git a/test/index.html b/test/index.html
index c7c2ae55d..4a8aef529 100644
--- a/test/index.html
+++ b/test/index.html
@@ -203,6 +203,7 @@ Z</textarea>
<select name="D4" disabled="disabled">
<option selected="selected" value="NO">NO</option>
</select>
+ <input name="id">
</form>
<div id="moretests">
<form>
diff --git a/test/unit/attributes.js b/test/unit/attributes.js
index b9605d152..5b6144462 100644
--- a/test/unit/attributes.js
+++ b/test/unit/attributes.js
@@ -69,7 +69,7 @@ test("prop(String, Object)", function() {
});
test("attr(String)", function() {
- expect(20);
+ expect(22);
equals( jQuery('#text1').attr('type'), "text", 'Check for type attribute' );
equals( jQuery('#radio1').attr('type'), "radio", 'Check for type attribute' );
@@ -82,8 +82,10 @@ test("attr(String)", function() {
equals( jQuery('#name').attr('name'), "name", 'Check for name attribute' );
equals( jQuery('#text1').attr('name'), "action", 'Check for name attribute' );
ok( jQuery('#form').attr('action').indexOf("formaction") >= 0, 'Check for action attribute' );
- // Temporarily disabled. See: #4299
- // ok( jQuery('#form').attr('action','newformaction').attr('action').indexOf("newformaction") >= 0, 'Check that action attribute was changed' );
+ // [7472] & [3113] (form contains an input with name="action" or name="id")
+ equals( jQuery('#form').attr('action','newformaction').attr('action'), 'newformaction', 'Check that action attribute was changed' );
+ equals( jQuery('#testForm').removeAttr('id').attr('id'), undefined, 'Test that id does not equal the input with name=id after id is removed [#7472]' );
+
equals( jQuery('#text1').attr('maxlength'), '30', 'Check for maxlength attribute' );
equals( jQuery('#text1').attr('maxLength'), '30', 'Check for maxLength attribute' );
equals( jQuery('#area1').attr('maxLength'), '30', 'Check for maxLength attribute' );