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(/(? -
+