html-proofer 2.5.0 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/html/proofer.rb +2 -1
- data/lib/html/proofer/check_runner.rb +1 -28
- data/lib/html/proofer/url_validator.rb +35 -2
- data/lib/html/proofer/version.rb +1 -1
- data/spec/html/proofer/links_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e3e81446e89bd9cd6e2bb65fdc374f02304c1d9f
|
4
|
+
data.tar.gz: f0fdfa24b5c7a5e8e5b2934adbc060f6ecbb9582
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 36b29e1f9bcc2a498fed44d1a0ddb3bfd725b2061b4a9d5493827238967ef74201209f5b1c103bf672ec6edab7de866d0dc94f40fe8c5a05891f2086f9fc9051
|
7
|
+
data.tar.gz: 0781163094e5a85ddde161a2e1e5b07b9fbe3903f004ec8766cb838f52048668b86a6212413b3c6974a2365f72359036f4c5bcc741a9634e5e2e2f5396af048c
|
data/lib/html/proofer.rb
CHANGED
@@ -22,7 +22,7 @@ module HTML
|
|
22
22
|
class Proofer
|
23
23
|
include HTML::Proofer::Utils
|
24
24
|
|
25
|
-
attr_reader :options, :typhoeus_opts, :hydra_opts, :parallel_opts, :validation_opts, :external_urls
|
25
|
+
attr_reader :options, :typhoeus_opts, :hydra_opts, :parallel_opts, :validation_opts, :external_urls, :iterable_external_urls
|
26
26
|
|
27
27
|
TYPHOEUS_DEFAULTS = {
|
28
28
|
:followlocation => true,
|
@@ -147,6 +147,7 @@ module HTML
|
|
147
147
|
def validate_urls
|
148
148
|
url_validator = HTML::Proofer::UrlValidator.new(logger, @external_urls, @options, @typhoeus_opts, @hydra_opts)
|
149
149
|
@failed_tests.concat(url_validator.run)
|
150
|
+
@iterable_external_urls = url_validator.iterable_external_urls
|
150
151
|
end
|
151
152
|
|
152
153
|
def files
|
@@ -24,7 +24,6 @@ module HTML
|
|
24
24
|
@alt_ignores = @options[:alt_ignore]
|
25
25
|
@empty_alt_ignore = @options[:empty_alt_ignore]
|
26
26
|
@external_urls = {}
|
27
|
-
@external_domain_paths_with_queries = {}
|
28
27
|
end
|
29
28
|
|
30
29
|
def run
|
@@ -37,13 +36,7 @@ module HTML
|
|
37
36
|
|
38
37
|
def add_to_external_urls(url, line)
|
39
38
|
return if @external_urls[url]
|
40
|
-
|
41
|
-
|
42
|
-
if uri.query.nil?
|
43
|
-
add_path_for_url(url)
|
44
|
-
else
|
45
|
-
new_url_query_values?(uri, url)
|
46
|
-
end
|
39
|
+
add_path_for_url(url)
|
47
40
|
end
|
48
41
|
|
49
42
|
def add_path_for_url(url)
|
@@ -54,26 +47,6 @@ module HTML
|
|
54
47
|
end
|
55
48
|
end
|
56
49
|
|
57
|
-
def new_url_query_values?(uri, url)
|
58
|
-
queries = uri.query_values.keys.join('-')
|
59
|
-
domain_path = extract_domain_path(uri)
|
60
|
-
if @external_domain_paths_with_queries[domain_path].nil?
|
61
|
-
add_path_for_url(url)
|
62
|
-
# remember queries we've seen, ignore future ones
|
63
|
-
@external_domain_paths_with_queries[domain_path] = [queries]
|
64
|
-
else
|
65
|
-
# add queries we haven't seen
|
66
|
-
unless @external_domain_paths_with_queries[domain_path].include?(queries)
|
67
|
-
add_path_for_url(url)
|
68
|
-
@external_domain_paths_with_queries[domain_path] << queries
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def extract_domain_path(uri)
|
74
|
-
uri.host + uri.path
|
75
|
-
end
|
76
|
-
|
77
50
|
def self.checks
|
78
51
|
classes = []
|
79
52
|
|
@@ -7,22 +7,55 @@ module HTML
|
|
7
7
|
class UrlValidator
|
8
8
|
include HTML::Proofer::Utils
|
9
9
|
|
10
|
-
attr_accessor :logger, :external_urls, :hydra
|
10
|
+
attr_accessor :logger, :external_urls, :iterable_external_urls, :hydra
|
11
11
|
|
12
12
|
def initialize(logger, external_urls, options, typhoeus_opts, hydra_opts)
|
13
13
|
@logger = logger
|
14
14
|
@external_urls = external_urls
|
15
|
+
@iterable_external_urls = {}
|
15
16
|
@failed_tests = []
|
16
17
|
@options = options
|
17
18
|
@hydra = Typhoeus::Hydra.new(hydra_opts)
|
18
19
|
@typhoeus_opts = typhoeus_opts
|
20
|
+
@external_domain_paths_with_queries = {}
|
19
21
|
end
|
20
22
|
|
21
23
|
def run
|
22
|
-
|
24
|
+
@iterable_external_urls = remove_query_values
|
25
|
+
external_link_checker(@iterable_external_urls)
|
23
26
|
@failed_tests
|
24
27
|
end
|
25
28
|
|
29
|
+
def remove_query_values
|
30
|
+
return if @external_urls.nil?
|
31
|
+
iterable_external_urls = @external_urls.dup
|
32
|
+
@external_urls.keys.each do |url|
|
33
|
+
uri = Addressable::URI.parse(url)
|
34
|
+
next if uri.query.nil?
|
35
|
+
iterable_external_urls.delete(url) unless new_url_query_values?(uri)
|
36
|
+
end
|
37
|
+
iterable_external_urls
|
38
|
+
end
|
39
|
+
|
40
|
+
# remember queries we've seen, ignore future ones
|
41
|
+
def new_url_query_values?(uri)
|
42
|
+
queries = uri.query_values.keys.join('-')
|
43
|
+
domain_path = extract_domain_path(uri)
|
44
|
+
if @external_domain_paths_with_queries[domain_path].nil?
|
45
|
+
@external_domain_paths_with_queries[domain_path] = [queries]
|
46
|
+
true
|
47
|
+
elsif !@external_domain_paths_with_queries[domain_path].include?(queries)
|
48
|
+
@external_domain_paths_with_queries[domain_path] << queries
|
49
|
+
true
|
50
|
+
else
|
51
|
+
false
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def extract_domain_path(uri)
|
56
|
+
uri.host + uri.path
|
57
|
+
end
|
58
|
+
|
26
59
|
# Proofer runs faster if we pull out all the external URLs and run the checks
|
27
60
|
# at the end. Otherwise, we're halting the consuming process for every file during
|
28
61
|
# the check_directory_of_files process.
|
data/lib/html/proofer/version.rb
CHANGED
@@ -371,6 +371,6 @@ describe 'Links test' do
|
|
371
371
|
it 'does not check links with parameters multiple times' do
|
372
372
|
fixture = "#{FIXTURES_DIR}/links/check_just_once.html"
|
373
373
|
proofer = run_proofer(fixture)
|
374
|
-
expect(proofer.
|
374
|
+
expect(proofer.iterable_external_urls.length).to eq 2
|
375
375
|
end
|
376
376
|
end
|