diff --git a/.ruby-version b/.ruby-version index e4604e3a..15a27998 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -3.2.1 +3.3.0 diff --git a/lib/html_proofer/attribute/url.rb b/lib/html_proofer/attribute/url.rb index 5c5c59f3..811517ec 100644 --- a/lib/html_proofer/attribute/url.rb +++ b/lib/html_proofer/attribute/url.rb @@ -52,7 +52,8 @@ def unknown_extension? def ignore? return true if /^javascript:/.match?(@url) - return true if ignores_pattern?(@runner.options[:ignore_urls]) + + true if ignores_pattern?(@runner.options[:ignore_urls]) end def valid? @@ -220,11 +221,24 @@ def without_hash @url.to_s.sub(/##{hash}/, "") end - # catch any obvious issues, like strings in port numbers + # catch any obvious issues private def clean_url! - return if @url =~ /^([!#{Regexp.last_match(0)}-;=?-\[\]_a-z~]|%[0-9a-fA-F]{2})+$/ - - @url = Addressable::URI.parse(@url).normalize.to_s + parsed_url = Addressable::URI.parse(@url) + url = if parsed_url.scheme.nil? + parsed_url + else + parsed_url.normalize + end.to_s + + # normalize strips this off, which causes issues with cache + @url = if @url.end_with?("/") && !url.end_with?("/") + "#{url}/" + elsif !@url.end_with?("/") && url.end_with?("/") + url.chop + else + url + end + rescue Addressable::URI::InvalidURIError # rubocop:disable Lint/SuppressedException; error will be reported at check time end private def swap_urls! diff --git a/lib/html_proofer/cache.rb b/lib/html_proofer/cache.rb index 92ae038c..ef0cf3c7 100644 --- a/lib/html_proofer/cache.rb +++ b/lib/html_proofer/cache.rb @@ -41,7 +41,7 @@ def initialize(runner, options) end def parsed_timeframe(timeframe) - return nil if timeframe.nil? + return if timeframe.nil? time, date = timeframe.match(/(\d+)(\D)/).captures time = time.to_i @@ -252,7 +252,7 @@ def size(type) SECONDS_PER_HOUR = 3600 SECONDS_PER_DAY = 86400 SECONDS_PER_WEEK = 604800 - SECONDS_PER_MONTH = 2629746 # 1/12 of a gregorian year + SECONDS_PER_MONTH = 2629746 # 1/12 of a gregorian year private def time_ago(measurement, unit) case unit @@ -269,7 +269,8 @@ def size(type) private def url_matches_type?(url, type) return true if type == :internal && url !~ URI_REGEXP - return true if type == :external && url =~ URI_REGEXP + + true if type == :external && url =~ URI_REGEXP end private def cleaned_url(url) diff --git a/lib/html_proofer/configuration.rb b/lib/html_proofer/configuration.rb index 88147a5c..58936306 100644 --- a/lib/html_proofer/configuration.rb +++ b/lib/html_proofer/configuration.rb @@ -233,8 +233,8 @@ def parse_cli_options(args) arg.split(",").each_with_object({}) do |s, hsh| split = s.split(/(? -

A real link

+

A real link

diff --git a/spec/html-proofer/fixtures/vcr_cassettes/links/unicode_domain_html_log_level_error_type_file_.yml b/spec/html-proofer/fixtures/vcr_cassettes/links/unicode_domain_html_log_level_error_type_file_.yml index 26cfc5e6..2bc6e344 100644 --- a/spec/html-proofer/fixtures/vcr_cassettes/links/unicode_domain_html_log_level_error_type_file_.yml +++ b/spec/html-proofer/fixtures/vcr_cassettes/links/unicode_domain_html_log_level_error_type_file_.yml @@ -2,13 +2,13 @@ http_interactions: - request: method: head - uri: https://xn--mxaaaiil1bdgepgr1bpt0d.gr/ + uri: https://xn--gran-8qa.fi body: encoding: US-ASCII string: '' headers: User-Agent: - - Mozilla/5.0 (compatible; HTML Proofer/3.19.3; +https://github.com/gjtorikian/html-proofer) + - Mozilla/5.0 (compatible; HTML Proofer/5.0.8; +https://github.com/gjtorikian/html-proofer) Accept: - application/xml,application/xhtml+xml,text/html;q=0.9, text/plain;q=0.8,image/png,*/*;q=0.5 Expect: @@ -16,33 +16,39 @@ http_interactions: response: status: code: 200 - message: OK + message: '' headers: - Date: - - Fri, 31 Dec 2021 16:37:41 GMT - Content-Type: - - text/html; charset=UTF-8 - Connection: - - keep-alive - x-powered-by: - - PHP/8.0.13 - x-turbo-charged-by: - - LiteSpeed - CF-Cache-Status: - - DYNAMIC - Report-To: - - '{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=vHwiFt05sw2oM%2BxOEY0YbwWDVJ7lNnaWzqt3YVttfW73qJj%2FOicx%2F2u6FF84ul4dFoAdtntXjMsZhHCWx2Q%2F2%2B842ECjjDJOLjPrkVdaHxBaMKnuzqJWI8j2aXzIKuRDADaWiYS6XcGYTXuEAXZg1g%3D%3D"}],"group":"cf-nel","max_age":604800}' - NEL: - - '{"success_fraction":0,"report_to":"cf-nel","max_age":604800}' - Server: - - cloudflare - CF-RAY: - - 6c64ef1218b18c4b-EWR + accept-ranges: + - bytes + access-control-allow-origin: + - "*" + age: + - '2084372' + cache-control: + - public, max-age=0, must-revalidate + content-disposition: + - inline + content-type: + - text/html; charset=utf-8 + date: + - Mon, 06 May 2024 22:16:55 GMT + etag: + - '"17bf20f1307387d12393425f77714bc2"' + server: + - Vercel + strict-transport-security: + - max-age=63072000 + x-vercel-cache: + - HIT + x-vercel-id: + - sfo1::jvrgm-1715033815794-3d4492f2b00f + content-length: + - '11213' body: encoding: ASCII-8BIT string: '' - http_version: '1.1' + http_version: '2' adapter_metadata: - effective_url: http://xn--mxaaaiil1bdgepgr1bpt0d.gr/ - recorded_at: Fri, 31 Dec 2021 16:37:41 GMT + effective_url: https://www.xn--gran-8qa.fi/ + recorded_at: Mon, 06 May 2024 22:16:55 GMT recorded_with: VCR 2.9.3 diff --git a/spec/html-proofer/maliciousness_spec.rb b/spec/html-proofer/maliciousness_spec.rb index 322588fa..7ded67e6 100644 --- a/spec/html-proofer/maliciousness_spec.rb +++ b/spec/html-proofer/maliciousness_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -describe "Maliciousness test" do # rubocop:disable RSpec/DescribeClass +describe "Maliciousness" do it "does not accept non-string input for single file" do expect do run_proofer(23, :file) diff --git a/spec/html-proofer/proofer_spec.rb b/spec/html-proofer/proofer_spec.rb index e23c7b34..fb6949c8 100644 --- a/spec/html-proofer/proofer_spec.rb +++ b/spec/html-proofer/proofer_spec.rb @@ -2,7 +2,9 @@ require "spec_helper" -describe HTMLProofer do +describe "Proofer" do + let(:described_class) { HTMLProofer } + describe "#failed_checks" do it "is an array of Failures" do broken_link_internal_filepath = File.join(FIXTURES_DIR, "links", "broken_link_internal.html") diff --git a/spec/html-proofer/cli_reporter_spec.rb b/spec/html-proofer/reporter/terminal_spec.rb similarity index 98% rename from spec/html-proofer/cli_reporter_spec.rb rename to spec/html-proofer/reporter/terminal_spec.rb index 40fc5655..f0d3328d 100644 --- a/spec/html-proofer/cli_reporter_spec.rb +++ b/spec/html-proofer/reporter/terminal_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -describe HTMLProofer::Reporter::Terminal do +describe "Reporter::Terminal" do describe "report" do it "reports all issues accurately" do error_file = File.join(FIXTURES_DIR, "sorting", "kitchen_sinkish.html") diff --git a/spec/html-proofer/reporter_spec.rb b/spec/html-proofer/reporter_spec.rb index 963a7cc5..fe56b178 100644 --- a/spec/html-proofer/reporter_spec.rb +++ b/spec/html-proofer/reporter_spec.rb @@ -8,7 +8,7 @@ def report end end -describe HTMLProofer::Reporter do +describe "Reporter" do it "supports a custom reporter" do file = File.join(FIXTURES_DIR, "sorting", "kitchen_sinkish.html") cassette_name = make_cassette_name(file, {}) diff --git a/spec/html-proofer/runner_spec.rb b/spec/html-proofer/runner_spec.rb index e6d53106..c50eee4a 100644 --- a/spec/html-proofer/runner_spec.rb +++ b/spec/html-proofer/runner_spec.rb @@ -2,7 +2,7 @@ require "spec_helper" -describe HTMLProofer::Runner do +describe "Runner" do describe "#before_request" do it "sends authorization header to github.com" do opts = {} diff --git a/spec/html-proofer/utils_spec.rb b/spec/html-proofer/utils_spec.rb index 1096ae49..49c95d63 100644 --- a/spec/html-proofer/utils_spec.rb +++ b/spec/html-proofer/utils_spec.rb @@ -2,9 +2,9 @@ require "spec_helper" -describe HTMLProofer::Utils do +describe "Utils" do describe "::create_nokogiri" do - include described_class + include HTMLProofer::Utils it "passes for a string" do noko = create_nokogiri('')