Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ gem "redcarpet"
gem "rubocop"
gem "rubocop-rspec"
gem "rubocop-standard"

gem "rspec", "~> 3.1"
gem "timecop", "~> 0.8"
gem "vcr", "~> 6.4"
4 changes: 0 additions & 4 deletions html-proofer.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,4 @@ Gem::Specification.new do |spec|
spec.add_dependency("typhoeus", "~> 1.3")
spec.add_dependency("yell", "~> 2.0")
spec.add_dependency("zeitwerk", "~> 2.5")

spec.add_development_dependency("rspec", "~> 3.1")
spec.add_development_dependency("timecop", "~> 0.8")
spec.add_development_dependency("vcr", "~> 6.4")
end
2 changes: 1 addition & 1 deletion lib/html_proofer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
require "debug"
begin
require "amazing_print"
rescue LoadError # rubocop:disable Lint/SuppressedException
rescue LoadError
end
end

Expand Down
6 changes: 4 additions & 2 deletions lib/html_proofer/attribute/url.rb
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,9 @@ def full_path
def unslashed_directory?(file)
return false unless File.directory?(file)

!file.end_with?(File::SEPARATOR) && !follow_location?
# the trailing slash must be read off the URL, not off `file`: the latter
# is produced by File.expand_path, which strips trailing separators
!path.to_s.end_with?("/") && !follow_location?
end

def follow_location?
Expand Down Expand Up @@ -239,7 +241,7 @@ def without_hash
else
url
end
rescue Addressable::URI::InvalidURIError # rubocop:disable Lint/SuppressedException -- error will be reported at check time
rescue Addressable::URI::InvalidURIError # -- error will be reported at check time
end

private def swap_urls!
Expand Down
5 changes: 4 additions & 1 deletion lib/html_proofer/url_validator/external.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,10 @@ def check_hash_in_2xx_response(href, url, response, filenames)
return false unless url.hash?

hash = url.hash
headers = response.options.fetch(:headers, {})
# `response.headers` covers both live responses (which expose the headers
# via :response_headers) and stubbed ones (which set :headers directly);
# reading options[:headers] saw nothing but stubs.
headers = response.headers || {}
content_type = headers.find { |k, _| k.casecmp("content-type").zero? }

# attempt to verify PDF hash ref; see #787 for more details
Expand Down
2 changes: 1 addition & 1 deletion lib/html_proofer/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module HTMLProofer
VERSION = "5.2.1"
VERSION = "5.2.2"
end
8 changes: 4 additions & 4 deletions spec/html-proofer/check/favicon_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
it "fails for absent favicon" do
absent = File.join(FIXTURES_DIR, "favicon", "favicon_absent.html")
proofer = run_proofer(absent, :file, checks: ["Favicon"])
expect(proofer.failed_checks.first.description).to(match(/no favicon provided/))
expect(proofer.failed_checks.first.description).to(include('no favicon provided'))
end

it "fails for absent favicon but present apple touch icon" do
Expand All @@ -23,7 +23,7 @@
it "fails for favicon missing the protocol" do
missing_protocol = File.join(FIXTURES_DIR, "favicon", "protocol_relative_favicon.html")
proofer = run_proofer(missing_protocol, :file)
expect(proofer.failed_checks.first.description).to(match(/protocol-relative URL/))
expect(proofer.failed_checks.first.description).to(include('protocol-relative URL'))
end

it "fails for broken internal favicon" do
Expand All @@ -41,7 +41,7 @@
it "fails for ignored with ignore_urls" do
ignored = File.join(FIXTURES_DIR, "favicon", "internal_favicon_broken.html")
proofer = run_proofer(ignored, :file, checks: ["Favicon"], ignore_urls: [/asdadaskdalsdk/])
expect(proofer.failed_checks.first.description).to(match(/no favicon provided/))
expect(proofer.failed_checks.first.description).to(include('no favicon provided'))
end

it "translates links via swap_urls" do
Expand Down Expand Up @@ -70,7 +70,7 @@
it "fails for broken favicon with data-proofer-ignore" do
broken_but_ignored = File.join(FIXTURES_DIR, "favicon", "favicon_broken_but_ignored.html")
proofer = run_proofer(broken_but_ignored, :file, checks: ["Favicon"])
expect(proofer.failed_checks.first.description).to(match(/no favicon provided/))
expect(proofer.failed_checks.first.description).to(include('no favicon provided'))
end

it "specifically ignores jekyll redirect_from template" do
Expand Down
12 changes: 6 additions & 6 deletions spec/html-proofer/check/images_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
it "fails for missing external images" do
external_image_filepath = File.join(FIXTURES_DIR, "images", "missing_image_external.html")
proofer = run_proofer(external_image_filepath, :file)
expect(proofer.failed_checks.first.description).to(match(/failed with something very wrong/))
expect(proofer.failed_checks.first.description).to(include('failed with something very wrong'))
end

it "fails for missing internal images" do
Expand All @@ -79,13 +79,13 @@
it "fails for image with no src" do
image_src_filepath = File.join(FIXTURES_DIR, "images", "missing_image_src.html")
proofer = run_proofer(image_src_filepath, :file)
expect(proofer.failed_checks.first.description).to(match(/image has no src or srcset attribute/))
expect(proofer.failed_checks.first.description).to(include('image has no src or srcset attribute'))
end

it "fails for image with default macOS filename" do
terrible_image_name = File.join(FIXTURES_DIR, "images", "terrible_image_name.html")
proofer = run_proofer(terrible_image_name, :file)
expect(proofer.failed_checks.first.description).to(match(/image has a terrible filename/))
expect(proofer.failed_checks.first.description).to(include('image has a terrible filename'))
end

it "ignores images marked as ignore data-proofer-ignore" do
Expand Down Expand Up @@ -125,7 +125,7 @@
it "fails for images missing the protocol" do
missing_protocol_link = File.join(FIXTURES_DIR, "images", "image_missing_protocol_valid.html")
proofer = run_proofer(missing_protocol_link, :file)
expect(proofer.failed_checks.first.description).to(match(/protocol-relative URL/))
expect(proofer.failed_checks.first.description).to(include('protocol-relative URL'))
end

it "properly checks relative links" do
Expand Down Expand Up @@ -185,7 +185,7 @@
it "fails for images with an alt but missing src or srcset" do
src_set_missing_alt = File.join(FIXTURES_DIR, "images", "src_set_missing_image.html")
proofer = run_proofer(src_set_missing_alt, :file)
expect(proofer.failed_checks.first.description).to(match(/image has no src or srcset attribute/))
expect(proofer.failed_checks.first.description).to(include('image has no src or srcset attribute'))
end

it "properly ignores missing alt tags when asked for srcset" do
Expand All @@ -209,7 +209,7 @@
it "fails for HTTP images when not asked" do
http = File.join(FIXTURES_DIR, "images", "src_http.html")
proofer = run_proofer(http, :file)
expect(proofer.failed_checks.first.description).to(match(/uses the http scheme/))
expect(proofer.failed_checks.first.description).to(include('uses the http scheme'))
end

it "properly checks relative images with base" do
Expand Down
Loading