html-proofer 3.18.2 → 3.18.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 852efb42767ef8589aa2f469f06c807ab287d78da04043e5a57e4d4a7f8bf6dd
4
- data.tar.gz: 065406c8f1a7978d025224dc4ef53137e698eaeec8f097c1375620c8d6e0c5ba
3
+ metadata.gz: 406cf6b61f0416a7f9f6874cd43e855288bc047ff7e2ec8ba374acdc57c1898b
4
+ data.tar.gz: fc44f71f75c1b830182d2ef60aed3abcc816ee7671cb7c4d74c174e75edf30be
5
5
  SHA512:
6
- metadata.gz: c5aabdd3e5087dd1282b4428b7105e62216b22510c1a73a9f80f1e6b2ba18906217c7aaa974b245644de2b325bef8fd3e05c61c528302fb59ce5a353da0c1d04
7
- data.tar.gz: 7155e2eed2e31173ad7e8efe4d7ce31b2cf18fa403b560f03428e3ef8ff8f9c60654f9e1ee6a4470ff65f609fdaeeb107e0236c85610212e90b7a9535a650522
6
+ metadata.gz: 47501eb3aa242423f2e748ed52d3fa5ed8c9ae35c839602d27de0b1712a0c1e22d8cfe20781569d469439ecc75bc3f853100f6aae63ee1c3f6174641cc102f7e
7
+ data.tar.gz: 30348fc2649b3210038813bf05e24f10d0ca775e1253a2ba04c79c282b1822bc3ed89e45c0652e44889b9bf82a6022fdc25db70407425c144b15875fe0c53ad0
@@ -11,6 +11,8 @@ module HTMLProofer
11
11
  DEFAULT_STORAGE_DIR = File.join('tmp', '.htmlproofer')
12
12
  DEFAULT_CACHE_FILE_NAME = 'cache.log'
13
13
 
14
+ URI_REGEXP = URI::DEFAULT_PARSER.make_regexp
15
+
14
16
  attr_reader :exists, :cache_log, :storage_dir, :cache_file
15
17
 
16
18
  def initialize(logger, options)
@@ -30,6 +32,8 @@ module HTMLProofer
30
32
  end
31
33
 
32
34
  def within_timeframe?(time)
35
+ return false if time.nil?
36
+
33
37
  (@parsed_timeframe..@cache_time).cover?(Time.parse(time))
34
38
  end
35
39
 
@@ -71,10 +75,14 @@ module HTMLProofer
71
75
  @cache_log[clean_url(url)] = data
72
76
  end
73
77
 
74
- def detect_url_changes(found)
75
- existing_urls = @cache_log.keys.map { |url| clean_url(url) }
78
+ def detect_url_changes(found, type)
76
79
  found_urls = found.keys.map { |url| clean_url(url) }
77
80
 
81
+ # if there were no urls, bail
82
+ return {} if found_urls.empty?
83
+
84
+ existing_urls = @cache_log.keys.map { |url| clean_url(url) }
85
+
78
86
  # prepare to add new URLs detected
79
87
  additions = found.reject do |url, _|
80
88
  url = clean_url(url)
@@ -91,24 +99,28 @@ module HTMLProofer
91
99
  @logger.log :info, "Adding #{new_link_text} to the cache..."
92
100
 
93
101
  # remove from cache URLs that no longer exist
94
- del = 0
102
+ deletions = 0
95
103
  @cache_log.delete_if do |url, _|
96
104
  url = clean_url(url)
105
+
97
106
  if found_urls.include?(url)
98
107
  false
99
- else
108
+ elsif url_matches_type?(url, type)
100
109
  @logger.log :debug, "Removing #{url} from cache check"
101
- del += 1
110
+ deletions += 1
102
111
  true
103
112
  end
104
113
  end
105
114
 
106
- del_link_text = pluralize(del, 'link', 'links')
115
+ del_link_text = pluralize(deletions, 'link', 'links')
107
116
  @logger.log :info, "Removing #{del_link_text} from the cache..."
108
117
 
109
118
  additions
110
119
  end
111
120
 
121
+ # TODO: Garbage performance--both the external and internal
122
+ # caches need access to this file. Write a proper versioned
123
+ # schema in the future
112
124
  def write
113
125
  File.write(cache_file, @cache_log.to_json)
114
126
  end
@@ -117,12 +129,15 @@ module HTMLProofer
117
129
  @load.nil?
118
130
  end
119
131
 
120
- def retrieve_urls(urls)
121
- urls_to_check = detect_url_changes(urls)
132
+ def retrieve_urls(urls, type)
133
+ urls_to_check = detect_url_changes(urls, type)
134
+
122
135
  @cache_log.each_pair do |url, cache|
123
136
  next if within_timeframe?(cache['time']) && cache['message'].empty? # these were successes to skip
124
137
 
125
- urls_to_check[url] = cache['filenames'] # recheck expired links
138
+ if url_matches_type?(url, type)
139
+ urls_to_check[url] = cache['filenames'] # recheck expired links
140
+ end
126
141
  end
127
142
  urls_to_check
128
143
  end
@@ -149,9 +164,9 @@ module HTMLProofer
149
164
 
150
165
  @cache_file = File.join(storage_dir, cache_file_name)
151
166
 
152
- return unless File.exist?(cache_file)
167
+ return unless File.exist?(@cache_file)
153
168
 
154
- contents = File.read(cache_file)
169
+ contents = File.read(@cache_file)
155
170
  @cache_log = contents.empty? ? {} : JSON.parse(contents)
156
171
  end
157
172
 
@@ -169,5 +184,10 @@ module HTMLProofer
169
184
  @cache_datetime - Rational(measurement / 24.0)
170
185
  end.to_time
171
186
  end
187
+
188
+ def url_matches_type?(url, type)
189
+ return true if type == :internal && url !~ URI_REGEXP
190
+ return true if type == :external && url =~ URI_REGEXP
191
+ end
172
192
  end
173
193
  end
@@ -51,14 +51,16 @@ class LinkCheck < ::HTMLProofer::Check
51
51
  # curl/Typheous inaccurately return 404s for some links. cc https://git.io/vyCFx
52
52
  next if @link.respond_to?(:rel) && @link.rel == 'dns-prefetch'
53
53
 
54
+ unless @link.path?
55
+ add_issue("#{@link.href} is an invalid URL", line: line, content: content)
56
+ next
57
+ end
58
+
54
59
  add_to_external_urls(@link.href || @link.src)
55
60
  next
56
61
  elsif @link.internal?
57
- if @link.exists? || @link.hash
58
- add_to_internal_urls(@link.href, InternalLink.new(@link, @path, line, content))
59
- else
60
- add_issue("internally linking to #{@link.href}, which does not exist", line: line, content: content)
61
- end
62
+ add_to_internal_urls(@link.href, InternalLink.new(@link, @path, line, content))
63
+ add_issue("internally linking to #{@link.href}, which does not exist", line: line, content: content) if !@link.exists? && !@link.hash
62
64
  end
63
65
  end
64
66
 
@@ -24,7 +24,7 @@ module HTMLProofer
24
24
  raise e
25
25
  end
26
26
 
27
- @aria_hidden = defined?(@aria_hidden) && @aria_hidden == 'true' ? true : false
27
+ @aria_hidden = defined?(@aria_hidden) && @aria_hidden == 'true'
28
28
 
29
29
  @data_proofer_ignore = defined?(@data_proofer_ignore)
30
30
 
@@ -74,6 +74,10 @@ module HTMLProofer
74
74
  !parts.nil?
75
75
  end
76
76
 
77
+ def path?
78
+ !parts.host.nil? && !parts.path.nil?
79
+ end
80
+
77
81
  def parts
78
82
  @parts ||= Addressable::URI.parse url
79
83
  rescue URI::Error, Addressable::URI::InvalidURIError
@@ -216,6 +220,8 @@ module HTMLProofer
216
220
  end
217
221
 
218
222
  def ignores_pattern_check(links)
223
+ return false unless links.is_a?(Array)
224
+
219
225
  links.each do |ignore|
220
226
  case ignore
221
227
  when String
@@ -22,7 +22,7 @@ module HTMLProofer
22
22
  allow_hash_href: true,
23
23
  check_external_hash: true,
24
24
  check_html: true,
25
- url_ignore: [/.*/], # Don't try to check if local files exist
25
+ url_ignore: [%r{^/}], # Don't try to check if local files exist
26
26
  validation: { report_eof_tags: true }
27
27
  }
28
28
  end
@@ -63,7 +63,9 @@ module HTMLProofer
63
63
  swap(url, @options[:url_swap])
64
64
  end
65
65
  end
66
- @external_urls = Hash[*@src.map { |s| [s, nil] }.flatten]
66
+ @external_urls = @src.each_with_object({}) do |url, hash|
67
+ hash[url] = nil
68
+ end
67
69
  validate_external_urls
68
70
  end
69
71
 
@@ -123,7 +125,7 @@ module HTMLProofer
123
125
  end
124
126
 
125
127
  external_urls = check.external_urls
126
- external_urls = Hash[check.external_urls.map { |url, file| [swap(url, @options[:url_swap]), file] }] if @options[:url_swap]
128
+ external_urls = check.external_urls.map { |url, file| [swap(url, @options[:url_swap]), file] }.to_h if @options[:url_swap]
127
129
  result[:external_urls].merge!(external_urls)
128
130
  result[:failures].concat(check.issues)
129
131
  end
@@ -236,7 +238,7 @@ module HTMLProofer
236
238
  end
237
239
 
238
240
  def load_internal_cache
239
- urls_to_check = @cache.retrieve_urls(@internal_urls)
241
+ urls_to_check = @cache.retrieve_urls(@internal_urls, :internal)
240
242
  cache_text = pluralize(urls_to_check.count, 'internal link', 'internal links')
241
243
  @logger.log :info, "Found #{cache_text} in the cache..."
242
244
 
@@ -26,7 +26,7 @@ module HTMLProofer
26
26
  @external_urls = remove_query_values
27
27
 
28
28
  if @cache.use_cache?
29
- urls_to_check = @cache.retrieve_urls(@external_urls)
29
+ urls_to_check = @cache.retrieve_urls(@external_urls, :external)
30
30
  external_link_checker(urls_to_check)
31
31
  @cache.write
32
32
  else
@@ -85,7 +85,7 @@ module HTMLProofer
85
85
  # for HEAD. If we've decided to check for hashes, we must do a GET--HEAD is
86
86
  # not available as an option.
87
87
  def external_link_checker(external_urls)
88
- external_urls = Hash[external_urls.sort]
88
+ external_urls = external_urls.sort.to_h
89
89
 
90
90
  count = external_urls.length
91
91
  check_text = pluralize(count, 'external link', 'external links')
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTMLProofer
4
- VERSION = '3.18.2'
4
+ VERSION = '3.18.7'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: html-proofer
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.18.2
4
+ version: 3.18.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-17 00:00:00.000000000 Z
11
+ date: 2021-03-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable
@@ -285,9 +285,12 @@ require_paths:
285
285
  - lib
286
286
  required_ruby_version: !ruby/object:Gem::Requirement
287
287
  requirements:
288
- - - "~>"
288
+ - - ">="
289
+ - !ruby/object:Gem::Version
290
+ version: 2.4.10
291
+ - - "<"
289
292
  - !ruby/object:Gem::Version
290
- version: '2.4'
293
+ version: '4.0'
291
294
  required_rubygems_version: !ruby/object:Gem::Requirement
292
295
  requirements:
293
296
  - - ">="