html-proofer 4.0.0 → 4.2.0

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: b6e8293984dde05cd406326b21fa93a638b0a972efdab95f59adfe606e8be538
4
- data.tar.gz: b9323e2c6d7cf91a08f45a7b9ecb77b826c02b2ad2b6bf74e6951701b41c3bdb
3
+ metadata.gz: 916656620e369529ae71be63c4316ba627afcf97d2f60b4ce963e375f772a7b8
4
+ data.tar.gz: 83e751f1ec8bf453c2612cf1d34ef24e3de1d7620d740be1f8c392627f39cc85
5
5
  SHA512:
6
- metadata.gz: 6d962362e0abc03b2deb15da0b06f2e42857756b045db568c959263346957b628dee73b719de2ed9f24a03762e2ae97e2ff208ea8f216c6d0323bca77864d43d
7
- data.tar.gz: 2bb9ca1d81e1a088344c8df0c513d2c0e96187cf23b7895def81fba4ac1820f56a0099a4dd2caa861df6ecd75afd4388e4a5b37e18308c4641300ab07f704d15
6
+ metadata.gz: c396512e2262ba0bbeab69ee602c42c522cdec4f7b9036e81808011e4b6d47e06188baeaa86524361166af90ce1751b3f08e4075b437b28eab8c4c6bec065630
7
+ data.tar.gz: e2e660641cca01f1501b69dda405808624ec03b4ebaa0a9c12618f82e77314f94adbc459ec343898f548be5676f763d11d69bf5cbbebf154148490e49b304f83
data/bin/htmlproofer CHANGED
@@ -21,10 +21,11 @@ Mercenary.program(:htmlproofer) do |p|
21
21
  p.option 'assume_extension', '--assume-extension <ext>', 'Automatically add specified extension to files for internal links, to allow extensionless URLs (as supported by most servers) (default: `.html`).'
22
22
  p.option 'checks', '--checks check1,[check2,...]', Array, 'A comma-separated list of Strings indicating which checks you want to run (default: `["Links", "Images", "Scripts"]`)'
23
23
  p.option 'check_external_hash', '--check-external-hash', 'Checks whether external hashes exist (even if the webpage exists) (default: `true`).'
24
+ p.option 'check_internal_hash', '--check-internal-hash', 'Checks whether internal hashes exist (even if the webpage exists) (default: `true`).'
24
25
  p.option 'check_sri', '--check-sri', 'Check that `<link>` and `<script>` external resources use SRI (default: `false`).'
25
26
  p.option 'directory_index_file', '--directory-index-file <filename>', String, 'Sets the file to look for when a link refers to a directory. (default: `index.html`)'
26
27
  p.option 'disable_external', '--disable-external', 'If `true`, does not run the external link checker (default: `false`)'
27
- p.option 'enforce_https', '--enforce-https', 'Fails a link if it\'s not marked as `https` (default: `true`).'
28
+ p.option 'enforce_https', '--enforce-https <false>', String, 'Fails a link if it\'s not marked as `https` (default: `true`).'
28
29
  p.option 'extensions', '--extensions ext1,[ext2,...[', Array, 'A comma-separated list of Strings indicating the file extensions you would like to check (including the dot) (default: `.html`)'
29
30
  p.option 'ignore_empty_alt', '--ignore-empty-alt', ' If `true`, ignores images with empty/missing alt tags (in other words, `<img alt>` and `<img alt="">` are valid; set this to `false` to flag those)'
30
31
  p.option 'ignore_files', '--ignore-files file1,[file2,...]', Array, 'A comma-separated list of Strings or RegExps containing file paths that are safe to ignore'
@@ -67,6 +68,8 @@ Mercenary.program(:htmlproofer) do |p|
67
68
  end
68
69
  end
69
70
 
71
+ options[:enforce_https] = false if opts['enforce_https'] == "false"
72
+
70
73
  options[:log_level] = opts['log_level'].to_sym unless opts['log_level'].nil?
71
74
 
72
75
  options[:typhoeus] = HTMLProofer::Configuration.parse_json_option('typhoeus', opts['typhoeus'], symbolize_names: false) unless opts['typhoeus'].nil?
@@ -161,7 +161,13 @@ module HTMLProofer
161
161
  end
162
162
 
163
163
  def unslashed_directory?(file)
164
- File.directory?(file) && !file.end_with?(File::SEPARATOR)
164
+ return false unless File.directory?(file)
165
+
166
+ !file.end_with?(File::SEPARATOR) && !follow_location?
167
+ end
168
+
169
+ def follow_location?
170
+ @runner.options[:typhoeus] && @runner.options[:typhoeus][:followlocation]
165
171
  end
166
172
 
167
173
  def absolute_path?(path)
@@ -20,12 +20,21 @@ module HTMLProofer
20
20
  add_failure("image has no src or srcset attribute", line: @img.line, content: @img.content)
21
21
  elsif @img.url.remote?
22
22
  add_to_external_urls(@img.url, @img.line)
23
- elsif !@img.url.exists? && !@img.multiple_srcsets?
23
+ elsif !@img.url.exists? && !@img.multiple_srcsets? && !@img.multiple_sizes?
24
24
  add_failure("internal image #{@img.url.raw_attribute} does not exist", line: @img.line,
25
25
  content: @img.content)
26
26
  elsif @img.multiple_srcsets?
27
- srcsets = @img.srcset.split(",").map(&:strip)
28
- srcsets.each do |srcset|
27
+ @img.srcsets.each do |srcset|
28
+ srcset_url = HTMLProofer::Attribute::Url.new(@runner, srcset, base_url: @img.base_url)
29
+
30
+ if srcset_url.remote?
31
+ add_to_external_urls(srcset_url.url, @img.line)
32
+ elsif !srcset_url.exists?
33
+ add_failure("internal image #{srcset} does not exist", line: @img.line, content: @img.content)
34
+ end
35
+ end
36
+ elsif @img.multiple_sizes?
37
+ @img.srcsets_wo_sizes.each do |srcset|
29
38
  srcset_url = HTMLProofer::Attribute::Url.new(@runner, srcset, base_url: @img.base_url)
30
39
 
31
40
  if srcset_url.remote?
@@ -9,6 +9,7 @@ module HTMLProofer
9
9
  allow_missing_href: false,
10
10
  assume_extension: ".html",
11
11
  check_external_hash: true,
12
+ check_internal_hash: true,
12
13
  checks: DEFAULT_TESTS,
13
14
  directory_index_file: "index.html",
14
15
  disable_external: false,
@@ -84,6 +84,28 @@ module HTMLProofer
84
84
  !blank?(srcset) && srcset.split(",").size > 1
85
85
  end
86
86
 
87
+ def srcsets
88
+ return nil if blank?(srcset)
89
+
90
+ srcset.split(",").map(&:strip)
91
+ end
92
+
93
+ def multiple_sizes?
94
+ return false if blank?(srcsets)
95
+
96
+ srcsets.any? do |srcset|
97
+ !blank?(srcset) && srcset.split(" ").size > 1
98
+ end
99
+ end
100
+
101
+ def srcsets_wo_sizes
102
+ return nil if blank?(srcsets)
103
+
104
+ srcsets.map do |srcset|
105
+ srcset.split(" ").first
106
+ end
107
+ end
108
+
87
109
  def ignore?
88
110
  return true if @node.attributes["data-proofer-ignore"]
89
111
  return true if ancestors_ignorable?
@@ -68,6 +68,7 @@ module HTMLProofer
68
68
  private def hash_exists?(url)
69
69
  href_hash = url.hash
70
70
  return true if blank?(href_hash)
71
+ return true unless @runner.options[:check_internal_hash]
71
72
 
72
73
  # prevents searching files we didn't ask about
73
74
  return false unless url.known_extension?
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module HTMLProofer
4
- VERSION = "4.0.0"
4
+ VERSION = "4.2.0"
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: 4.0.0
4
+ version: 4.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garen Torikian
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-07-11 00:00:00.000000000 Z
11
+ date: 2022-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: addressable