Media: Ensure empty `alt` attributes are set to blank strings.

This is a follow up to [38065] to ensure that `wp.html.string()` always
converts empty `alt` attributes to `alt=""` rather than returning HTML using
empty attribute notation, like `alt`. This allows screen readers to ignore
images with empty `alt` attributes, rather than reading out the URL string.

Additionally this completely removes the logic in `wp.html.string()` for
converting blank attributes to empty attribute notation since empty attribute
notation is generally meant to denote a boolean value, e.g.,
`checked` == `checked="checked"`, which doesn't apply in this context because
boolean attributes must be omitted in order to represent a `false` value.
See: https://www.w3.org/TR/html5/infrastructure.html#boolean-attributes

Props adamsilverstein, afineman, joemcgill.
Fixes #36735.

git-svn-id: https://develop.svn.wordpress.org/trunk@38116 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Joe McGill 2016-07-20 14:37:24 +00:00
parent e284dafbc7
commit 1bda0a6e2e
1 changed files with 0 additions and 5 deletions

View File

@ -326,11 +326,6 @@ window.wp = window.wp || {};
_.each( options.attrs, function( value, attr ) {
text += ' ' + attr;
// Use empty attribute notation where possible.
if ( '' === value ) {
return;
}
// Convert boolean values to strings.
if ( _.isBoolean( value ) ) {
value = value ? 'true' : 'false';