Skip to content

Commit 3ecb630

Browse files
authored
Merge pull request #851 from paulroub/srcset-sizes-fail
Handle multiple srcsets when first is remote (fixes #850)
2 parents 5903360 + f44aa4c commit 3ecb630

21 files changed

+353
-24
lines changed

.rubocop.yml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ inherit_gem:
22
rubocop-standard:
33
- config/default.yml
44

5-
require:
5+
plugins:
66
- rubocop-rspec
77

88
Naming/FileName:
@@ -14,8 +14,11 @@ RSpec/AnyInstance:
1414
RSpec/ExampleLength:
1515
Enabled: false
1616

17-
RSpec/FilePath:
18-
Enabled: false
17+
# RSpec/SpecFilePathFormat:
18+
# Enabled: false
19+
20+
# RSpec/SpecFilePathSuffix:
21+
# Enabled: false
1922

2023
RSpec/MultipleExpectations:
2124
Enabled: false

lib/html_proofer/attribute/url.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ def without_hash
238238
else
239239
url
240240
end
241-
rescue Addressable::URI::InvalidURIError # rubocop:disable Lint/SuppressedException; error will be reported at check time
241+
rescue Addressable::URI::InvalidURIError # rubocop:disable Lint/SuppressedException -- error will be reported at check time
242242
end
243243

244244
private def swap_urls!

lib/html_proofer/check/images.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,6 @@ def run
2020
# does the image exist?
2121
if missing_src?
2222
add_failure("image has no src or srcset attribute", element: @img)
23-
elsif @img.url.protocol_relative?
24-
add_failure(
25-
"image link #{@img.url} is a protocol-relative URL, use explicit https:// instead",
26-
element: @img,
27-
)
28-
elsif @img.url.remote?
29-
add_to_external_urls(@img.url, @img.line)
30-
elsif !@img.url.exists? && !@img.multiple_srcsets? && !@img.multiple_sizes?
31-
add_failure(
32-
"internal image #{@img.url.raw_attribute} does not exist",
33-
element: @img,
34-
)
3523
elsif @img.multiple_srcsets? || @img.multiple_sizes?
3624
@img.srcsets_wo_sizes.each do |srcset|
3725
srcset_url = HTMLProofer::Attribute::Url.new(@runner, srcset, base_url: @img.base_url, source: @img.url.source, filename: @img.url.filename, extract_size: true)
@@ -47,6 +35,18 @@ def run
4735
add_failure("internal image #{srcset} does not exist", element: @img)
4836
end
4937
end
38+
elsif @img.url.protocol_relative?
39+
add_failure(
40+
"image link #{@img.url} is a protocol-relative URL, use explicit https:// instead",
41+
element: @img,
42+
)
43+
elsif @img.url.remote?
44+
add_to_external_urls(@img.url, @img.line)
45+
elsif !@img.url.exists? && !@img.multiple_srcsets? && !@img.multiple_sizes?
46+
add_failure(
47+
"internal image #{@img.url.raw_attribute} does not exist",
48+
element: @img,
49+
)
5050
end
5151

5252
# if this is an img element, check that the alt attribute is present

lib/html_proofer/log.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Log
1313
def initialize(log_level)
1414
@logger = Yell.new(
1515
format: false,
16-
name: "HTMLProofer", \
16+
name: "HTMLProofer",
1717
level: "gte.#{log_level}",
1818
) do |l|
1919
l.adapter(:stdout, level: "lte.warn")

lib/html_proofer/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module HTMLProofer
4-
VERSION = "5.0.9"
4+
VERSION = "5.0.10"
55
end

spec/html-proofer/cache_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ def read_cache(cache_filename)
526526
external_link = cache["external"]["https://github.com/gjtorikian/html-proofer"]
527527
expect(external_link["found"]).to(equal(true))
528528
expect(external_link["status_code"]).to(equal(200))
529-
expect(external_link["message"]).equal?("OK")
529+
expect(external_link["message"]).to(match("OK"))
530530

531531
File.delete(cache_filepath)
532532
end

spec/html-proofer/check/images_spec.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,12 @@
278278
expect(proofer.failed_checks).to(eq([]))
279279
end
280280

281+
it "works for picture elements with multiple remote sizes" do
282+
custom_data_src_check = "#{FIXTURES_DIR}/images/srcset_picture_remote_sizes.html"
283+
proofer = run_proofer(custom_data_src_check, :file)
284+
expect(proofer.failed_checks).to(eq([]))
285+
end
286+
281287
it "breaks for picture elements with multiple srcsets and pixel densities" do
282288
custom_data_src_check = "#{FIXTURES_DIR}/images/srcset_picture_pixel-density_broken.html"
283289
proofer = run_proofer(custom_data_src_check, :file)

spec/html-proofer/cli_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@
216216
it "has only one UA" do
217217
http = make_bin(%|--typhoeus='{"verbose":true,"headers":{"User-Agent":"Mozilla/5.0 (Macintosh; My New User-Agent)"}}' --as-links https://linkedin.com|)
218218
expect(http.scan("User-Agent: Typhoeus").count).to(eq(0))
219-
expect(http.scan(%r{User-Agent: Mozilla/5.0 \(Macintosh; My New User-Agent\)}i).count).to(eq(2))
219+
expect(http.match(%r{User-Agent: Mozilla/5.0 \(Macintosh; My New User-Agent\)}i)).not_to(be_nil)
220220
end
221221

222222
it "supports hydra" do
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":2,"internal":{"/somewhere.html":{"time":"2022-01-06 12:00:00 -0700","metadata":[{"source":"spec/html-proofer/fixtures/cache/internal_and_external_example.html","filename":"spec/html-proofer/fixtures/cache/internal_and_external_example.html","line":11,"base_url":"","found":false}]}},"external":{"https://github.com/gjtorikian/html-proofer":{"time":"2022-01-06 12:00:00 -0700","found":true,"status_code":200,"message":"OK","metadata":[{"filename":"spec/html-proofer/fixtures/cache/internal_and_external_example.html","line":7}]}}}
1+
{"version":2,"internal":{"/somewhere.html":{"time":"2022-01-06 12:00:00 -0500","metadata":[{"source":"spec/html-proofer/fixtures/cache/internal_and_external_example.html","filename":"spec/html-proofer/fixtures/cache/internal_and_external_example.html","line":11,"base_url":"","found":false}]}},"external":{"https://github.com/gjtorikian/html-proofer":{"time":"2022-01-06 12:00:00 -0500","found":true,"status_code":200,"message":"OK","metadata":[{"filename":"spec/html-proofer/fixtures/cache/internal_and_external_example.html","line":7}]}}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":2,"internal":{},"external":{"https://github.com/gjtorikian/html-proofer":{"time":"2022-01-06 12:00:00 -0700","found":true,"status_code":200,"message":"OK","metadata":[{"filename":"spec/html-proofer/fixtures/cache/external_example.html","line":7}]}}}
1+
{"version":2,"internal":{},"external":{"https://github.com/gjtorikian/html-proofer":{"time":"2022-01-06 12:00:00 -0500","found":true,"status_code":200,"message":"OK","metadata":[{"filename":"spec/html-proofer/fixtures/cache/external_example.html","line":7}]}}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":2,"internal":{},"external":{"https://github.com/gjtorikian":{"time":"2022-01-06 12:00:00 -0700","found":true,"status_code":200,"message":"OK","metadata":[{"filename":"spec/html-proofer/fixtures/cache/some_link.html","line":7}]}}}
1+
{"version":2,"internal":{},"external":{"https://github.com/gjtorikian":{"time":"2022-01-06 12:00:00 -0500","found":true,"status_code":200,"message":"OK","metadata":[{"filename":"spec/html-proofer/fixtures/cache/some_link.html","line":7}]}}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"version":2,"internal":{},"external":{"https://www.github.com":{"time":"2022-02-17 12:00:00 -0700","found":true,"status_code":200,"message":"OK","metadata":[{"filename":"spec/html-proofer/fixtures/links/_site/folder.html/index.html","line":4}]}}}
1+
{"version":2,"internal":{},"external":{"https://www.github.com":{"time":"2022-02-17 12:00:00 -0500","found":true,"status_code":200,"message":"OK","metadata":[{"filename":"spec/html-proofer/fixtures/links/_site/folder.html/index.html","line":4}]}}}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<picture>
2+
<!--[if IE 9]><video style="display: none;"><![endif]-->
3+
<source
4+
srcset="
5+
https://upload.wikimedia.org/wikipedia/en/thumb/2/22/Heckert_GNU_white.svg/256px-Heckert_GNU_white.svg.png 2x,
6+
https://upload.wikimedia.org/wikipedia/en/2/22/Heckert_GNU_white.svg 1x
7+
"
8+
type="image/webp"
9+
/>
10+
<!--[if IE 9]></video><![endif]-->
11+
<img srcset="gpl.png" alt="test" />
12+
</picture>

spec/html-proofer/fixtures/vcr_cassettes/fixtures/links_extensions_xhtml_foo_log_level_error_type_directory_.yml

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/html-proofer/fixtures/vcr_cassettes/links/bad_external_links_html_log_level_error_type_file_.yml

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/html-proofer/fixtures/vcr_cassettes/links/broken_link_external_html_log_level_error_type_file_.yml

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/html-proofer/fixtures/vcr_cassettes/links/empty_href_html_log_level_error_type_file_.yml

Lines changed: 87 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/html-proofer/fixtures/vcr_cassettes/links/file_foo_extensions_foo_log_level_error_type_file_.yml

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/html-proofer/fixtures/vcr_cassettes/links/non_standard_characters_html_log_level_error_type_file_.yml

Lines changed: 71 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spec/html-proofer/fixtures/vcr_cassettes/links/source_html_log_level_error_type_file_.yml

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)