jquery/test/unit
Michał Gołębiowski-Owczarek 063831b637
Attributes: Make .attr( name, false ) remove for all non-ARIA attrs
The HTML spec defines boolean attributes:
https://html.spec.whatwg.org/#boolean-attributes
that often correlate with boolean properties. If the attribute is missing, it
correlates with the `false` property value, if it's present - the `true`
property value. The only valid values are an empty string or the attribute name.

jQuery tried to be helpful here and treated boolean attributes in a special way
in the `.attr()` API:
1. For the getter, as long as the attribute was present, it was returning the
   attribute name lowercased, ignoring the value.
2. For the setter, it was removing the attribute when `false` was passed;
   otherwise, it was ignoring the passed value and set the attribute -
   interestingly, in jQuery `>=3` not lowercased anymore.

The problem is the spec occasionally converts boolean attributes into ones with
additional attribute values with special behavior - one such example is the new
`"until-found"` value for the `hidden` attribute. Our setter normalization
means passing those values is impossible with jQuery. Also, new boolean
attributes are introduced occasionally and jQuery cannot easily add them to the
list without incurring breaking changes.

This patch removes any special handling of boolean attributes - the getter
returns the value as-is and the setter sets the provided value.

To provide better backwards compatibility with the very frequent `false` value
provided to remove the attribute, this patch makes `false` trigger attribute
removal for ALL non-ARIA attributes. ARIA attributes are exempt from the rule
since many of them recognize `"false"` as a valid value with semantics different
than the attribute missing. To remove an ARIA attribute, use `.removeAttr()` or
pass `null` as the value to `.attr()` which doesn't have this exception.

Fixes gh-5388
Closes gh-5452

Co-authored-by: Richard Gibson <richard.gibson@gmail.com>
2024-03-20 00:46:30 +01:00
..
ajax.js Tests: migrate testing infrastructure to minimal dependencies 2024-02-26 09:42:10 -05:00
animation.js Tests: migrate testing infrastructure to minimal dependencies 2024-02-26 09:42:10 -05:00
attributes.js Attributes: Make .attr( name, false ) remove for all non-ARIA attrs 2024-03-20 00:46:30 +01:00
basic.js Tests: Exclude tests based on compilation flags, not API presence 2022-06-28 12:39:01 +02:00
callbacks.js Build: migrate most grunt tasks off of grunt 2023-09-18 12:39:00 -04:00
core.js CSS:Selector: Align with 3.x, remove the outer selector.js wrapper 2023-09-20 02:31:35 +02:00
css.js Tests: Use allowlist instead of whitelist 2024-03-01 00:40:41 +01:00
data.js Build: migrate most grunt tasks off of grunt 2023-09-18 12:39:00 -04:00
deferred.js Build: migrate most grunt tasks off of grunt 2023-09-18 12:39:00 -04:00
deprecated.js Build: migrate most grunt tasks off of grunt 2023-09-18 12:39:00 -04:00
dimensions.js Core: Simplify code post browser support reduction 2023-09-20 00:54:40 +02:00
effects.js Build: migrate most grunt tasks off of grunt 2023-09-18 12:39:00 -04:00
event.js Tests: migrate testing infrastructure to minimal dependencies 2024-02-26 09:42:10 -05:00
exports.js Build: Update test code for compatibility with QUnit 2.x (#4297) 2019-02-18 19:03:26 +01:00
manipulation.js Tests: migrate testing infrastructure to minimal dependencies 2024-02-26 09:42:10 -05:00
offset.js Build: migrate most grunt tasks off of grunt 2023-09-18 12:39:00 -04:00
queue.js Build: migrate most grunt tasks off of grunt 2023-09-18 12:39:00 -04:00
ready.js Tests: Exclude tests based on compilation flags, not API presence 2022-06-28 12:39:01 +02:00
selector.js Attributes: Make .attr( name, false ) remove for all non-ARIA attrs 2024-03-20 00:46:30 +01:00
serialize.js Build: migrate most grunt tasks off of grunt 2023-09-18 12:39:00 -04:00
support.js Tests: migrate testing infrastructure to minimal dependencies 2024-02-26 09:42:10 -05:00
traversing.js Build: migrate most grunt tasks off of grunt 2023-09-18 12:39:00 -04:00
tween.js Tests: Exclude tests based on compilation flags, not API presence 2022-06-28 12:39:01 +02:00
wrap.js Core: Simplify code post browser support reduction 2023-09-20 00:54:40 +02:00