Skip to content

Commit 4e7a26b

Browse files
committed
Merge branch 'main' into v5
2 parents 2d22272 + 6f8a324 commit 4e7a26b

File tree

6 files changed

+139
-16
lines changed

6 files changed

+139
-16
lines changed

CHANGELOG.md

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,88 @@
22

33
## [Unreleased](https://github.com/gjtorikian/html-proofer/tree/HEAD)
44

5-
[Full Changelog](https://github.com/gjtorikian/html-proofer/compare/v4.2.0...HEAD)
5+
[Full Changelog](https://github.com/gjtorikian/html-proofer/compare/v4.4.2...HEAD)
6+
7+
**Merged pull requests:**
8+
9+
- Revert "Validate options" [\#774](https://github.com/gjtorikian/html-proofer/pull/774) ([gjtorikian](https://github.com/gjtorikian))
10+
11+
## [v4.4.2](https://github.com/gjtorikian/html-proofer/tree/v4.4.2) (2022-10-07)
12+
13+
[Full Changelog](https://github.com/gjtorikian/html-proofer/compare/v4.4.1...v4.4.2)
14+
15+
**Closed issues:**
16+
17+
- `erstiebegrüßung.html` causing problems on macOS [\#771](https://github.com/gjtorikian/html-proofer/issues/771)
18+
- HTMLProofer times out [\#768](https://github.com/gjtorikian/html-proofer/issues/768)
19+
20+
**Merged pull requests:**
21+
22+
- Create erstiebegrüßung.html from code [\#772](https://github.com/gjtorikian/html-proofer/pull/772) ([asbjornu](https://github.com/asbjornu))
23+
- Validate options [\#767](https://github.com/gjtorikian/html-proofer/pull/767) ([asbjornu](https://github.com/asbjornu))
24+
25+
## [v4.4.1](https://github.com/gjtorikian/html-proofer/tree/v4.4.1) (2022-09-25)
26+
27+
[Full Changelog](https://github.com/gjtorikian/html-proofer/compare/v4.4.0...v4.4.1)
28+
29+
**Closed issues:**
30+
31+
- Custom `Checker` class is not executed [\#764](https://github.com/gjtorikian/html-proofer/issues/764)
32+
- `--cache` unvailable in CLI [\#763](https://github.com/gjtorikian/html-proofer/issues/763)
33+
- `--parallel` unavailable in CLI [\#762](https://github.com/gjtorikian/html-proofer/issues/762)
34+
- HTMLproofer does not properly ignore links [\#756](https://github.com/gjtorikian/html-proofer/issues/756)
35+
- Mailto check failed in some cases [\#754](https://github.com/gjtorikian/html-proofer/issues/754)
36+
37+
**Merged pull requests:**
38+
39+
- Optimize checking internal link hashes in target files [\#770](https://github.com/gjtorikian/html-proofer/pull/770) ([riccardoporreca](https://github.com/riccardoporreca))
40+
- Fix `--swap-attributes` CLI argument in README [\#765](https://github.com/gjtorikian/html-proofer/pull/765) ([mark-monteiro](https://github.com/mark-monteiro))
41+
- Fix and improve swap\_attribute README example [\#755](https://github.com/gjtorikian/html-proofer/pull/755) ([riccardoporreca](https://github.com/riccardoporreca))
42+
43+
## [v4.4.0](https://github.com/gjtorikian/html-proofer/tree/v4.4.0) (2022-08-13)
44+
45+
[Full Changelog](https://github.com/gjtorikian/html-proofer/compare/v4.3.2...v4.4.0)
46+
47+
**Closed issues:**
48+
49+
- `--assume_extension` unexpected behaviour [\#751](https://github.com/gjtorikian/html-proofer/issues/751)
50+
- Protocol-relative \(no `http(s):`\) URL issue: Script cache issue and anti-pattern consideration [\#750](https://github.com/gjtorikian/html-proofer/issues/750)
51+
- Questions on command-line options in 4.x [\#749](https://github.com/gjtorikian/html-proofer/issues/749)
52+
53+
**Merged pull requests:**
54+
55+
- Fail on protocol-relative urls [\#752](https://github.com/gjtorikian/html-proofer/pull/752) ([riccardoporreca](https://github.com/riccardoporreca))
56+
57+
## [v4.3.2](https://github.com/gjtorikian/html-proofer/tree/v4.3.2) (2022-08-03)
58+
59+
[Full Changelog](https://github.com/gjtorikian/html-proofer/compare/v4.3.1...v4.3.2)
60+
61+
**Closed issues:**
62+
63+
- 4.3.1 Ignoring options [\#748](https://github.com/gjtorikian/html-proofer/issues/748)
64+
- Link checker triggered for href="" [\#746](https://github.com/gjtorikian/html-proofer/issues/746)
65+
- Passing RegExp to `--ignore-url` broken after v4.2.0 release [\#745](https://github.com/gjtorikian/html-proofer/issues/745)
66+
67+
**Merged pull requests:**
68+
69+
- Switch 'source' elements to use image check code path [\#747](https://github.com/gjtorikian/html-proofer/pull/747) ([fallax](https://github.com/fallax))
70+
71+
## [v4.3.1](https://github.com/gjtorikian/html-proofer/tree/v4.3.1) (2022-07-29)
72+
73+
[Full Changelog](https://github.com/gjtorikian/html-proofer/compare/v4.3.0...v4.3.1)
74+
75+
**Closed issues:**
76+
77+
- ignore\_files no longer works with regex [\#743](https://github.com/gjtorikian/html-proofer/issues/743)
78+
- Empty mailto is generating undesired errors. [\#742](https://github.com/gjtorikian/html-proofer/issues/742)
79+
80+
**Merged pull requests:**
81+
82+
- Srcsets - better handling of multiple srcsets [\#744](https://github.com/gjtorikian/html-proofer/pull/744) ([fallax](https://github.com/fallax))
83+
84+
## [v4.3.0](https://github.com/gjtorikian/html-proofer/tree/v4.3.0) (2022-07-26)
85+
86+
[Full Changelog](https://github.com/gjtorikian/html-proofer/compare/v4.2.0...v4.3.0)
687

788
**Closed issues:**
889

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ values. The escape sequences `\:` should be used to produce literal
198198
htmlproofer --swap-urls "wow:cow,mow:doh" --extensions .html.erb --ignore-urls www.github.com ./out
199199
```
200200

201-
Some configuration options--such as `--typheous`, `--cache`, or `--attribute-swap`--require well-formatted JSON.
201+
Some configuration options, such as `--typheous`, `--cache`, or `--swap-attributes`, require well-formatted JSON.
202202

203203
#### Adjusting for a `baseurl`
204204

lib/html_proofer/url_validator/internal.rb

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,39 @@ def validate
2222
end
2323

2424
def run_internal_link_checker(links)
25+
# collect urls and metadata for hashes to be checked in the same target file
26+
file_paths_hashes_to_check = {}
2527
to_add = []
26-
links.each_pair do |link, matched_files|
28+
links.each_with_index do |(link, matched_files), i|
29+
matched_count_to_log = pluralize(matched_files.count, "reference", "references")
30+
@logger.log(:debug, "(#{i + 1} / #{links.count}) Internal link #{link}: Checking #{matched_count_to_log}")
2731
matched_files.each do |metadata|
2832
url = HTMLProofer::Attribute::Url.new(@runner, link, base_url: metadata[:base_url])
2933

3034
@runner.current_source = metadata[:source]
3135
@runner.current_filename = metadata[:filename]
3236

33-
unless file_exists?(url)
37+
target_file_path = url.absolute_path
38+
unless file_exists?(target_file_path)
3439
@failed_checks << Failure.new(@runner.current_filename, "Links > Internal",
3540
"internally linking to #{url}, which does not exist", line: metadata[:line], status: nil, content: nil)
3641
to_add << [url, metadata, false]
3742
next
3843
end
3944

40-
unless hash_exists?(url)
45+
hash_exists = hash_exists_for_url?(url)
46+
if hash_exists.nil?
47+
# the hash needs to be checked in the target file, we collect the url and metadata
48+
unless file_paths_hashes_to_check.key?(target_file_path)
49+
file_paths_hashes_to_check[target_file_path] = {}
50+
end
51+
unless file_paths_hashes_to_check[target_file_path].key?(url.hash)
52+
file_paths_hashes_to_check[target_file_path][url.hash] = []
53+
end
54+
file_paths_hashes_to_check[target_file_path][url.hash] << [url, metadata]
55+
next
56+
end
57+
unless hash_exists
4158
@failed_checks << Failure.new(@runner.current_filename, "Links > Internal",
4259
"internally linking to #{url}; the file exists, but the hash '#{url.hash}' does not", line: metadata[:line], status: nil, content: nil)
4360
to_add << [url, metadata, false]
@@ -48,6 +65,24 @@ def run_internal_link_checker(links)
4865
end
4966
end
5067

68+
# check hashes by target file
69+
@logger.log(:info, "Checking internal link hashes in #{pluralize(file_paths_hashes_to_check.count, "file", "files")}")
70+
file_paths_hashes_to_check.each_with_index do |(file_path, hashes_to_check), i|
71+
hash_count_to_log = pluralize(hashes_to_check.count, "hash", "hashes")
72+
@logger.log(:debug, "(#{i + 1} / #{file_paths_hashes_to_check.count}) Checking #{hash_count_to_log} in #{file_path}")
73+
html = create_nokogiri(file_path)
74+
hashes_to_check.each_pair do |href_hash, url_metadata|
75+
exists = hash_exists_in_html?(href_hash, html)
76+
url_metadata.each do |(url, metadata)|
77+
unless exists
78+
@failed_checks << Failure.new(metadata[:filename], "Links > Internal",
79+
"internally linking to #{url}; the file exists, but the hash '#{href_hash}' does not", line: metadata[:line], status: nil, content: nil)
80+
end
81+
to_add << [url, metadata, exists]
82+
end
83+
end
84+
end
85+
5186
# adding directly to the cache above results in an endless loop
5287
to_add.each do |(url, metadata, exists)|
5388
@cache.add_internal(url.to_s, metadata, exists)
@@ -56,15 +91,15 @@ def run_internal_link_checker(links)
5691
@failed_checks
5792
end
5893

59-
private def file_exists?(url)
60-
absolute_path = url.absolute_path
61-
return @runner.checked_paths[url.absolute_path] if @runner.checked_paths.key?(absolute_path)
94+
private def file_exists?(absolute_path)
95+
return @runner.checked_paths[absolute_path] if @runner.checked_paths.key?(absolute_path)
6296

63-
@runner.checked_paths[url.absolute_path] = File.exist?(absolute_path)
97+
@runner.checked_paths[absolute_path] = File.exist?(absolute_path)
6498
end
6599

66-
# verify the target hash
67-
private def hash_exists?(url)
100+
# verify the hash w/o just based on the URL, w/o looking at the target file
101+
# => returns nil if the has could not be verified
102+
private def hash_exists_for_url?(url)
68103
href_hash = url.hash
69104
return true if blank?(href_hash)
70105
return true unless @runner.options[:check_internal_hash]
@@ -76,10 +111,18 @@ def run_internal_link_checker(links)
76111
decoded_href_hash = Addressable::URI.unescape(href_hash)
77112
fragment_ids = [href_hash, decoded_href_hash]
78113
# https://www.w3.org/TR/html5/single-page.html#scroll-to-fragid
79-
fragment_ids.include?("top") || !find_fragments(fragment_ids, url).empty?
114+
return true if fragment_ids.include?("top")
115+
116+
nil
117+
end
118+
119+
private def hash_exists_in_html?(href_hash, html)
120+
decoded_href_hash = Addressable::URI.unescape(href_hash)
121+
fragment_ids = [href_hash, decoded_href_hash]
122+
!find_fragments(fragment_ids, html).empty?
80123
end
81124

82-
private def find_fragments(fragment_ids, url)
125+
private def find_fragments(fragment_ids, html)
83126
xpaths = fragment_ids.uniq.flat_map do |frag_id|
84127
escaped_frag_id = "'#{frag_id.split("'").join("', \"'\", '")}', ''"
85128
[
@@ -89,7 +132,6 @@ def run_internal_link_checker(links)
89132
end
90133
xpaths << XpathFunctions.new
91134

92-
html = create_nokogiri(url.absolute_path)
93135
html.xpath(*xpaths)
94136
end
95137
end

lib/html_proofer/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module HTMLProofer
4-
VERSION = "4.4.0"
4+
VERSION = "4.4.3"
55
end

script/changelog

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/sh
22

3-
CHANGELOG_GITHUB_TOKEN="$PUBLIC_GITHUB_TOKEN" github_changelog_generator -u gjtorikian -p html-proofer
3+
CHANGELOG_GITHUB_TOKEN="$GITHUB_CHANGELOG_TOKEN" github_changelog_generator -u gjtorikian -p html-proofer

spec/html-proofer/fixtures/links/erstiebegrüßung.html

Whitespace-only changes.

0 commit comments

Comments
 (0)