From f76dfec537d55b95a1aaf23355764760c199234d Mon Sep 17 00:00:00 2001 From: antpb Date: Wed, 10 Oct 2018 11:33:53 -0500 Subject: [PATCH] fixes #1520 by adding validation that the Alt value is not empty --- packages/block-library/src/image/edit.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/image/edit.js b/packages/block-library/src/image/edit.js index d54638785f3e74..665212f7d1e95c 100644 --- a/packages/block-library/src/image/edit.js +++ b/packages/block-library/src/image/edit.js @@ -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( { @@ -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, } );