html-proofer 1.1.3 → 1.1.4
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 +4 -4
- data/README.md +1 -0
- data/html-proofer.gemspec +1 -1
- data/lib/html/proofer/check.rb +8 -1
- data/lib/html/proofer/checkable.rb +22 -11
- data/lib/html/proofer/checks/favicon.rb +1 -1
- data/lib/html/proofer/checks/images.rb +1 -1
- data/lib/html/proofer/checks/links.rb +2 -1
- data/lib/html/proofer/checks/scripts.rb +1 -1
- data/spec/html/proofer/fixtures/images/ignoreAltButNotLink.html +13 -0
- data/spec/html/proofer/fixtures/links/javascript_link.html +9 -0
- data/spec/html/proofer/images_spec.rb +7 -0
- data/spec/html/proofer/links_spec.rb +6 -0
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4077b1e7e65c5e6051a6be8f04eb7559a34924f6
|
4
|
+
data.tar.gz: 603ea3af05b2c946cfe9754026bb77f3ca2c4ef2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b5b02acf24b0b9594e721b646214de7065f84e4751a33eddcb8771b6bd99909f0b610724fa8637bb8f9ac6b3c42c96cf76bf8f60531b76665421d64c4289ab3
|
7
|
+
data.tar.gz: 773db8da60a145eaca7b70068d48a41bf885193d9825fb9e23f0e2000754992f1d1f551572222777e35b96fe007708266907b2de66cdec4ad70b2aaa2a292359
|
data/README.md
CHANGED
@@ -123,6 +123,7 @@ The `HTML::Proofer` constructor takes an optional hash of additional options:
|
|
123
123
|
| `disable_external` | If `true`, does not run the external link checker, which can take a lot of time. | `false` |
|
124
124
|
| `ext` | The extension of your HTML files including the dot. | `.html`
|
125
125
|
| `favicon` | Enables the favicon checker. | `false` |
|
126
|
+
| `followlocation` | Follows external redirections. Amends missing trailing slashes to internal directories. | `true` |
|
126
127
|
| `as_link_array` | Assumes that you've passed in just an array of links to check. | `false` |
|
127
128
|
| `href_ignore` | An array of Strings or RegExps containing `href`s that are safe to ignore. Certain URIs, like `mailto` and `tel`, are always ignored. | `[]` |
|
128
129
|
| `alt_ignore` | An array of Strings or RegExps containing `img`s whose missing `alt` tags are safe to ignore. | `[]` |
|
data/html-proofer.gemspec
CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
5
|
gem.name = "html-proofer"
|
6
|
-
gem.version = "1.1.
|
6
|
+
gem.version = "1.1.4"
|
7
7
|
gem.authors = ["Garen Torikian"]
|
8
8
|
gem.email = ["gjtorikian@gmail.com"]
|
9
9
|
gem.description = %q{Test your rendered HTML files to make sure they're accurate.}
|
data/lib/html/proofer/check.rb
CHANGED
@@ -15,7 +15,7 @@ class HTML::Proofer::Checks
|
|
15
15
|
def initialize(src, path, html, opts={})
|
16
16
|
@src = src
|
17
17
|
@path = path
|
18
|
-
@html = html
|
18
|
+
@html = remove_ignored(html)
|
19
19
|
@options = opts
|
20
20
|
@issues = []
|
21
21
|
@additional_href_ignores = @options[:href_ignore]
|
@@ -54,5 +54,12 @@ class HTML::Proofer::Checks
|
|
54
54
|
classes
|
55
55
|
end
|
56
56
|
|
57
|
+
private
|
58
|
+
|
59
|
+
def remove_ignored(html)
|
60
|
+
html.css("code, pre").each { |node| node.unlink }
|
61
|
+
html
|
62
|
+
end
|
63
|
+
|
57
64
|
end
|
58
65
|
end
|
@@ -62,17 +62,16 @@ module HTML
|
|
62
62
|
end
|
63
63
|
|
64
64
|
def ignore?
|
65
|
-
return true if @data_ignore_proofer
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
end
|
65
|
+
return true if @data_ignore_proofer
|
66
|
+
|
67
|
+
case @type
|
68
|
+
when "favicon"
|
69
|
+
return true if url.match(/^data:image/)
|
70
|
+
when "link"
|
71
|
+
return true if ignores_pattern_check(@check.additional_href_ignores)
|
72
|
+
when "image"
|
73
|
+
return true if url.match(/^data:image/)
|
74
|
+
return true if ignores_pattern_check(@check.additional_alt_ignores)
|
76
75
|
end
|
77
76
|
|
78
77
|
uri = URI.parse url
|
@@ -124,6 +123,18 @@ module HTML
|
|
124
123
|
path = file_path || @check.path
|
125
124
|
File.expand_path path, Dir.pwd
|
126
125
|
end
|
126
|
+
|
127
|
+
def ignores_pattern_check(links)
|
128
|
+
links.each do |ignore|
|
129
|
+
if ignore.is_a? String
|
130
|
+
return true if ignore == url
|
131
|
+
elsif ignore.is_a? Regexp
|
132
|
+
return true if ignore =~ url
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
false
|
137
|
+
end
|
127
138
|
end
|
128
139
|
end
|
129
140
|
end
|
@@ -11,7 +11,7 @@ class Favicons < ::HTML::Proofer::Checks::Check
|
|
11
11
|
def run
|
12
12
|
return unless @options[:favicon]
|
13
13
|
|
14
|
-
@html.
|
14
|
+
@html.css("link").each do |favicon|
|
15
15
|
favicon = Favicon.new favicon, "favicon", self
|
16
16
|
return if favicon.rel.split(" ").last.eql? "icon"
|
17
17
|
end
|
@@ -19,10 +19,11 @@ end
|
|
19
19
|
class Links < ::HTML::Proofer::Checks::Check
|
20
20
|
|
21
21
|
def run
|
22
|
-
@html.
|
22
|
+
@html.css("a, link").each do |l|
|
23
23
|
link = Link.new l, "link", self
|
24
24
|
|
25
25
|
next if link.ignore?
|
26
|
+
next if link.href =~ /^javascript:/ # can't put this in ignore? because the URI does not parse
|
26
27
|
|
27
28
|
# is it even a valid URL?
|
28
29
|
unless link.valid?
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<html>
|
2
|
+
|
3
|
+
<body>
|
4
|
+
|
5
|
+
<a href="javascript:if(typeof WZXYxe58==typeof alert)WZXYxe58();(function(){var s=document.createElement('link');s.setAttribute('href','/static/css/dyslexia.css');s.setAttribute('rel','stylesheet');s.setAttribute('type','text/css');document.getElementsByTagName('head')[0].appendChild(s);})();">Click me</a>
|
6
|
+
|
7
|
+
</body>
|
8
|
+
|
9
|
+
</html>
|
@@ -88,4 +88,11 @@ describe "Images test" do
|
|
88
88
|
output = capture_stderr { HTML::Proofer.new(ignorableLinks, {:alt_ignore => [/wikimedia/, "gpl.png"]}).run }
|
89
89
|
output.should == ""
|
90
90
|
end
|
91
|
+
|
92
|
+
it 'properly ignores missing alt tags, but not all URLs, when asked' do
|
93
|
+
ignorableLinks = "#{FIXTURES_DIR}/images/ignoreAltButNotLink.html"
|
94
|
+
output = capture_stderr { HTML::Proofer.new(ignorableLinks, {:alt_ignore => [/.*/]}).run }
|
95
|
+
output.should match /Couldn't resolve host name/
|
96
|
+
output.should_not match /does not have an alt attribute/
|
97
|
+
end
|
91
98
|
end
|
@@ -129,6 +129,12 @@ describe "Links test" do
|
|
129
129
|
output.should match /tel: is an invalid URL/
|
130
130
|
end
|
131
131
|
|
132
|
+
it 'ignores javascript links' do
|
133
|
+
javascriptLink = "#{FIXTURES_DIR}/links/javascript_link.html"
|
134
|
+
output = capture_stderr { HTML::Proofer.new(javascriptLink).run }
|
135
|
+
output.should == ""
|
136
|
+
end
|
137
|
+
|
132
138
|
it "works for valid links missing the protocol" do
|
133
139
|
missingProtocolLink = "#{FIXTURES_DIR}/links/link_missing_protocol_valid.html"
|
134
140
|
output = capture_stderr { HTML::Proofer.new(missingProtocolLink).run }
|
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: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Garen Torikian
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-07-
|
11
|
+
date: 2014-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mercenary
|
@@ -171,6 +171,7 @@ files:
|
|
171
171
|
- spec/html/proofer/fixtures/images/gpl.png
|
172
172
|
- spec/html/proofer/fixtures/images/ignorableAltViaOptions.html
|
173
173
|
- spec/html/proofer/fixtures/images/ignorableImages.html
|
174
|
+
- spec/html/proofer/fixtures/images/ignoreAltButNotLink.html
|
174
175
|
- spec/html/proofer/fixtures/images/image_missing_protocol_invalid.html
|
175
176
|
- spec/html/proofer/fixtures/images/image_missing_protocol_valid.html
|
176
177
|
- spec/html/proofer/fixtures/images/missingImageAlt.html
|
@@ -203,6 +204,7 @@ files:
|
|
203
204
|
- spec/html/proofer/fixtures/links/ignorableLinks.html
|
204
205
|
- spec/html/proofer/fixtures/links/ignorableLinksViaOptions.html
|
205
206
|
- spec/html/proofer/fixtures/links/index.html
|
207
|
+
- spec/html/proofer/fixtures/links/javascript_link.html
|
206
208
|
- spec/html/proofer/fixtures/links/linkToFolder.html
|
207
209
|
- spec/html/proofer/fixtures/links/linkTranslatedViaHrefSwap.html
|
208
210
|
- spec/html/proofer/fixtures/links/linkWithHttps.html
|
@@ -274,6 +276,7 @@ test_files:
|
|
274
276
|
- spec/html/proofer/fixtures/images/gpl.png
|
275
277
|
- spec/html/proofer/fixtures/images/ignorableAltViaOptions.html
|
276
278
|
- spec/html/proofer/fixtures/images/ignorableImages.html
|
279
|
+
- spec/html/proofer/fixtures/images/ignoreAltButNotLink.html
|
277
280
|
- spec/html/proofer/fixtures/images/image_missing_protocol_invalid.html
|
278
281
|
- spec/html/proofer/fixtures/images/image_missing_protocol_valid.html
|
279
282
|
- spec/html/proofer/fixtures/images/missingImageAlt.html
|
@@ -306,6 +309,7 @@ test_files:
|
|
306
309
|
- spec/html/proofer/fixtures/links/ignorableLinks.html
|
307
310
|
- spec/html/proofer/fixtures/links/ignorableLinksViaOptions.html
|
308
311
|
- spec/html/proofer/fixtures/links/index.html
|
312
|
+
- spec/html/proofer/fixtures/links/javascript_link.html
|
309
313
|
- spec/html/proofer/fixtures/links/linkToFolder.html
|
310
314
|
- spec/html/proofer/fixtures/links/linkTranslatedViaHrefSwap.html
|
311
315
|
- spec/html/proofer/fixtures/links/linkWithHttps.html
|