]> source.dussan.org Git - jquery.git/commitdiff
Fix for custom attr handles duck-punching the boolean attr handle
authorTimmy Willison <timmywillisn@gmail.com>
Wed, 28 Aug 2013 16:12:37 +0000 (12:12 -0400)
committerTimmy Willison <timmywillisn@gmail.com>
Wed, 28 Aug 2013 16:12:37 +0000 (12:12 -0400)
src/attributes/attr.js
test/unit/attributes.js

index 2a32b960cee88b8c7e48390745fe291893dcca59..6fb4d7f7fc9a75d585b1bd965241cbfa27be1fbb 100644 (file)
@@ -145,17 +145,19 @@ boolHook = {
 // Retrieve booleans specially
 jQuery.each( jQuery.expr.match.bool.source.match( /\w+/g ), function( i, name ) {
 
-       var getter = attrHandle[ name ] || jQuery.find.attr,
-       fn = attrHandle[ name ] = getSetInput && getSetAttribute || !ruseDefault.test( name ) ?
+       var getter = attrHandle[ name ] || jQuery.find.attr;
+
+       attrHandle[ name ] = getSetInput && getSetAttribute || !ruseDefault.test( name ) ?
                function( elem, name, isXML ) {
-                       var ret;
+                       var ret, handle;
                        if ( !isXML ) {
                                // Avoid an infinite loop by temporarily removing this function from the getter
+                               handle = attrHandle[ name ];
                                attrHandle[ name ] = ret;
                                ret = getter( elem, name, isXML ) != null ?
                                        name.toLowerCase() :
                                        null;
-                               attrHandle[ name ] = fn;
+                               attrHandle[ name ] = handle;
                        }
                        return ret;
                } :
index aa9d3b48cb3e4a2c5cb87e3b2ff39ba6475046b4..dc34f9df7e3af1d9e3db704069a3d82e02599ee9 100644 (file)
@@ -473,6 +473,20 @@ test( "attr(String, Object)", function() {
        equal( jQuery("#name").attr( "nonexisting", undefined ).attr("nonexisting"), undefined, ".attr('attribute', undefined) does not create attribute (#5571)" );
 });
 
+test( "attr - extending the boolean attrHandle", function() {
+       expect( 1 );
+       var called = false,
+               _handle = jQuery.expr.attrHandle.checked || $.noop;
+       jQuery.expr.attrHandle.checked = function() {
+               called = true;
+               _handle.apply( this, arguments );
+       };
+       jQuery( "input" ).attr( "checked" );
+       called = false;
+       jQuery( "input" ).attr( "checked" );
+       ok( called, "The boolean attrHandle does not drop custom attrHandles" );
+});
+
 test( "attr(String, Object) - Loaded via XML document", function() {
        expect( 2 );
        var xml = createDashboardXML(),