Skip to content

Commit

Permalink
fixup! Attributes: Restore boolean attribute & false setter treatment…
Browse files Browse the repository at this point in the history
… from 3.x
  • Loading branch information
mgol committed Oct 28, 2024
1 parent 65a03af commit 41905cc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
6 changes: 4 additions & 2 deletions src/jquery/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ jQuery.each( booleans.split( "|" ), function( _i, name ) {
attrValue = elem.getAttribute( name );

if ( attrValue !== name && attrValue != null &&
( extraBoolAttrValues[ name ] || [] ).indexOf( attrValue ) === -1
( extraBoolAttrValues[ name ] || [] )
.indexOf( String( attrValue ).toLowerCase() ) === -1
) {
migrateWarn( "boolean-attributes",
"Boolean attribute '" + name +
Expand All @@ -53,7 +54,8 @@ jQuery.each( booleans.split( "|" ), function( _i, name ) {
set: origAttrHooks.set || function( elem, value, name ) {
if ( jQuery.migrateIsPatchEnabled( "boolean-attributes" ) ) {
if ( value !== name &&
( extraBoolAttrValues[ name ] || [] ).indexOf( value ) === -1
( extraBoolAttrValues[ name ] || [] )
.indexOf( String( value ).toLowerCase() ) === -1
) {
if ( value !== false ) {
migrateWarn( "boolean-attributes",
Expand Down
19 changes: 18 additions & 1 deletion test/unit/jquery/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ QUnit.module( "attributes" );
QUnit.test( ".attr( boolean attribute ) - patch " +
( patchEnabled ? "enabled" : "disabled" ),
function( assert ) {
assert.expect( 31 );
assert.expect( 33 );

if ( !patchEnabled ) {
jQuery.migrateDisablePatches( "boolean-attributes" );
Expand Down Expand Up @@ -187,6 +187,23 @@ QUnit.module( "attributes" );
"Setting aria attributes to false is not affected by boolean settings"
);
} );

expectNoWarning( assert, "extra ex-boolean attrs values", function() {
var $input = jQuery( "<input />" );

$input.attr( "hidden", "until-found" );

if ( jQueryVersionSince( "4.0.0" ) ) {
assert.equal(
$input.attr( "hidden" ),
"until-found",
"Extra values of ex-boolean attributes are not changed"
);
} else {
assert.ok( true,
"Extra ex-boolean attrs values not supported under jQuery 3.x" );
}
} );
} );
}

Expand Down

0 comments on commit 41905cc

Please sign in to comment.