Skip to content

Commit

Permalink
fixes WordPress#1520 by adding validation that the Alt value is not e…
Browse files Browse the repository at this point in the history
…mpty
  • Loading branch information
antpb committed Oct 10, 2018
1 parent 2fe8cc0 commit f76dfec
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/block-library/src/image/edit.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,14 @@ class ImageEdit extends Component {
}
}

checkAltValue( altText, filename ) {
if ( ! altText ) {
this.props.setAttributes( { alt: 'This image has an empty alt attribute, the file name is ' + filename } );
return;
}
this.props.setAttributes( { alt: altText } );
}

onSelectImage( media ) {
if ( ! media || ! media.url ) {
this.props.setAttributes( {
Expand All @@ -120,8 +128,9 @@ class ImageEdit extends Component {
} );
return;
}
this.checkAltValue( media.alt, media.filename );
this.props.setAttributes( {
...pick( media, [ 'alt', 'id', 'caption', 'url' ] ),
...pick( media, [ 'id', 'caption', 'url' ] ),
width: undefined,
height: undefined,
} );
Expand Down

0 comments on commit f76dfec

Please sign in to comment.