diff --git a/lib/html_proofer/attribute/url.rb b/lib/html_proofer/attribute/url.rb index a7104778..5fc0c671 100644 --- a/lib/html_proofer/attribute/url.rb +++ b/lib/html_proofer/attribute/url.rb @@ -3,18 +3,20 @@ module HTMLProofer class Attribute class Url < HTMLProofer::Attribute - attr_reader :url + attr_reader :url, :size REMOTE_SCHEMES = ["http", "https"].freeze - def initialize(runner, link_attribute, base_url: nil) + def initialize(runner, link_attribute, base_url: nil, extract_size: false) super if @raw_attribute.nil? @url = nil else @url = @raw_attribute.delete("\u200b").strip + @url, @size = @url.split(/\s+/) if extract_size @url = Addressable::URI.join(base_url, @url).to_s unless blank?(base_url) + @url = "" if @url.nil? swap_urls! clean_url! diff --git a/lib/html_proofer/check/images.rb b/lib/html_proofer/check/images.rb index 977b8ae6..7ae8a4fe 100644 --- a/lib/html_proofer/check/images.rb +++ b/lib/html_proofer/check/images.rb @@ -25,7 +25,7 @@ def run content: @img.content) elsif @img.multiple_srcsets? @img.srcsets.each do |srcset| - srcset_url = HTMLProofer::Attribute::Url.new(@runner, srcset, base_url: @img.base_url) + srcset_url = HTMLProofer::Attribute::Url.new(@runner, srcset, base_url: @img.base_url, extract_size: true) if srcset_url.remote? add_to_external_urls(srcset_url.url, @img.line) @@ -35,7 +35,7 @@ def run end elsif @img.multiple_sizes? @img.srcsets_wo_sizes.each do |srcset| - srcset_url = HTMLProofer::Attribute::Url.new(@runner, srcset, base_url: @img.base_url) + srcset_url = HTMLProofer::Attribute::Url.new(@runner, srcset, base_url: @img.base_url, extract_size: true) if srcset_url.remote? add_to_external_urls(srcset_url.url, @img.line) diff --git a/spec/html-proofer/fixtures/images/webp/user_1200x1200_fit_q75_h2_lanczos.webp b/spec/html-proofer/fixtures/images/webp/user_1200x1200_fit_q75_h2_lanczos.webp new file mode 100644 index 00000000..122741b6 Binary files /dev/null and b/spec/html-proofer/fixtures/images/webp/user_1200x1200_fit_q75_h2_lanczos.webp differ diff --git a/spec/html-proofer/fixtures/images/webp/user_400.webp b/spec/html-proofer/fixtures/images/webp/user_400.webp new file mode 100644 index 00000000..122741b6 Binary files /dev/null and b/spec/html-proofer/fixtures/images/webp/user_400.webp differ diff --git a/spec/html-proofer/fixtures/images/webp/user_760.webp b/spec/html-proofer/fixtures/images/webp/user_760.webp new file mode 100644 index 00000000..122741b6 Binary files /dev/null and b/spec/html-proofer/fixtures/images/webp/user_760.webp differ diff --git a/spec/html-proofer/fixtures/images/webp_valid.html b/spec/html-proofer/fixtures/images/webp_valid.html new file mode 100644 index 00000000..02e8b42b --- /dev/null +++ b/spec/html-proofer/fixtures/images/webp_valid.html @@ -0,0 +1,10 @@ + + +
+ User::round +
+ + diff --git a/spec/html-proofer/images_spec.rb b/spec/html-proofer/images_spec.rb index a3c9b001..6eae7531 100644 --- a/spec/html-proofer/images_spec.rb +++ b/spec/html-proofer/images_spec.rb @@ -259,4 +259,10 @@ proofer = run_proofer(custom_data_src_check, :file) expect(proofer.failed_checks.first.description).to(match(/foo.webp does not exist/)) end + + it "works for various webp images" do + custom_data_src_check = "#{FIXTURES_DIR}/images/webp_valid.html" + proofer = run_proofer(custom_data_src_check, :file) + expect(proofer.failed_checks).to(eq([])) + end end