Skip to content

Commit

Permalink
Merge pull request #327 from arvindsv/fix_alt_ignore_ignoring_image_e…
Browse files Browse the repository at this point in the history
…xistance

Properly ignore alt without ignoring image
  • Loading branch information
gjtorikian committed Apr 21, 2016
2 parents 0669699 + ca75135 commit 2c13757
Show file tree
Hide file tree
Showing 5 changed files with 144 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/html-proofer/check/images.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def run
end
end

if @img.alt.nil? || (empty_alt_tag? && !@img.ignore_empty_alt?)
if !@img.ignore_alt? && (@img.alt.nil? || (empty_alt_tag? && !@img.ignore_empty_alt?))
add_issue("image #{@img.url} does not have an alt attribute", line: line)
end
end
Expand Down
5 changes: 3 additions & 2 deletions lib/html-proofer/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def initialize(obj, check)
# fix up missing protocols
@href.insert 0, 'http:' if @href =~ %r{^//}
@src.insert 0, 'http:' if @src =~ %r{^//}
@srcset.insert 0, 'http:' if @srcset =~ %r{^//}
end

def url
Expand Down Expand Up @@ -76,9 +77,9 @@ def ignore?

# ignore user defined URLs
return true if ignores_pattern_check(@check.options[:url_ignore])
end

# ignore user defined alts
return false unless 'ImageCheck' == @type
def ignore_alt?
return true if ignores_pattern_check(@check.options[:alt_ignore])
end

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions spec/html-proofer/images_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
expect(proofer.failed_tests.first).to match(/failed: response code 0/)
end

it 'fails for missing internal images even when alt_ignore is set' do
internalImageFilepath = "#{FIXTURES_DIR}/images/missingImageInternal.html"
proofer = run_proofer(internalImageFilepath, :file, {:alt_ignore => [/.*/]})
expect(proofer.failed_tests.first).to match(/doesnotexist.png does not exist/)
end

it 'fails for missing internal images' do
internalImageFilepath = "#{FIXTURES_DIR}/images/missingImageInternal.html"
proofer = run_proofer(internalImageFilepath, :file)
Expand Down

0 comments on commit 2c13757

Please sign in to comment.