]> source.dussan.org Git - jquery.git/commitdiff
Test for a colon in attribute names for IE6/7. Fixes #1591.
authortimmywil <tim.willison@thisismedium.com>
Sun, 1 May 2011 21:09:50 +0000 (17:09 -0400)
committertimmywil <tim.willison@thisismedium.com>
Sun, 1 May 2011 21:09:50 +0000 (17:09 -0400)
src/attributes.js
test/unit/attributes.js

index ade38bcaf60bec5434bf9ff0079fa1da48650219..017a32da405bcb4130c347f46e441c99173b70a2 100644 (file)
@@ -7,6 +7,7 @@ var rclass = /[\n\t\r]/g,
        rfocusable = /^(?:button|input|object|select|textarea)$/i,
        rclickable = /^a(?:rea)?$/i,
        rspecial = /^(?:data-|aria-)/,
+       rinvalidChar = /\:/,
        formHook;
 
 jQuery.fn.extend({
@@ -308,7 +309,10 @@ jQuery.extend({
 
                // Get the appropriate hook, or the formHook
                // if getSetAttribute is not supported and we have form objects in IE6/7
-               hooks = jQuery.attrHooks[ name ] || ( jQuery.nodeName( elem, "form" ) && formHook );
+               hooks = jQuery.attrHooks[ name ] ||
+                       ( formHook && (jQuery.nodeName( elem, "form" ) || rinvalidChar.test( name )) ?
+                               formHook :
+                               undefined );
 
                if ( value !== undefined ) {
 
@@ -451,10 +455,11 @@ if ( !jQuery.support.getSetAttribute ) {
        // Use this for any attribute on a form in IE6/7
        formHook = jQuery.attrHooks.name = jQuery.attrHooks.value = jQuery.valHooks.button = {
                get: function( elem, name ) {
+                       var ret;
                        if ( name === "value" && !jQuery.nodeName( elem, "button" ) ) {
                                return elem.getAttribute( name );
                        }
-                       var ret = elem.getAttributeNode( name );
+                       ret = elem.getAttributeNode( name );
                        // Return undefined if not specified instead of empty string
                        return ret && ret.specified ?
                                ret.nodeValue :
index cfe676a63465ee298dcc9aa08ac61834176f8054..37e854d06946cbb51a4f9b364f44dfc92158b209 100644 (file)
@@ -77,7 +77,7 @@ test("prop(String, Object)", function() {
 });
 
 test("attr(String)", function() {
-       expect(35);
+       expect(37);
 
        equals( jQuery("#text1").attr("type"), "text", "Check for type attribute" );
        equals( jQuery("#radio1").attr("type"), "radio", "Check for type attribute" );
@@ -142,6 +142,10 @@ test("attr(String)", function() {
        equals( $button.attr("value"), "foobar", "Value retrieval on a button does not return innerHTML" );
        equals( $button.attr("value", "baz").html(), "text", "Setting the value does not change innerHTML" );
 
+       // Attributes with a colon on a table element (#1591)
+       equals( jQuery("#table").attr("test:attrib"), undefined, "Retrieving a non-existent attribute on a table with a colon does not throw an error." );
+       equals( jQuery("#table").attr("test:attrib", "foobar").attr("test:attrib"), "foobar", "Setting an attribute on a table with a colon does not throw an error." );
+
        ok( jQuery("<div/>").attr("doesntexist") === undefined, "Make sure undefined is returned when no attribute is found." );
        ok( jQuery().attr("doesntexist") === undefined, "Make sure undefined is returned when no element is there." );
 });