Skip to content

Commit

Permalink
Properly ignore alt without ignoring image
Browse files Browse the repository at this point in the history
* alt_ignore for an image does not ignore the whole image now. If it is missing, it will
  be reported.
* Also, this unearthed another issue, where srcset was not properly 'fixed' by prefixing
  it with http://.
  • Loading branch information
arvindsv committed Apr 15, 2016
1 parent 0669699 commit ca75135
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 ca75135

Please sign in to comment.