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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 82825927f1730ea04245db859aa3fb25f20843d5
4
- data.tar.gz: b0f8ed372c1a5b2c0ec7e52e5d0096351efd7d91
3
+ metadata.gz: 4077b1e7e65c5e6051a6be8f04eb7559a34924f6
4
+ data.tar.gz: 603ea3af05b2c946cfe9754026bb77f3ca2c4ef2
5
5
  SHA512:
6
- metadata.gz: f4baee97f59fc19632854b731ca42629f317990d15bf254e6089a8942c356f2ea283a97a9dc7408ef1a7333b2b00e1bb07299fbc83541630cdd9864d9b43e5a5
7
- data.tar.gz: 094d5a13e510277cf7976c8d79a4d8309d5392f7af4887d95384bcd950bb9dca78b66efefbb123594f6ac9de1a10046c10e9ca77a2cca161a75cdfdb078fa5e8
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.3"
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.}
@@ -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 || @check.additional_href_ignores.include?(url) || @check.additional_alt_ignores.include?(url)
66
- return true if (@type == "image" || @type == "favicon") && url.match(/^data:image/)
67
-
68
- [@check.additional_href_ignores, @check.additional_alt_ignores].each do |additional_ignore|
69
- additional_ignore.each do |ignore|
70
- if ignore.is_a? String
71
- return true if ignore == url
72
- elsif ignore.is_a? Regexp
73
- return true if ignore =~ url
74
- end
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.xpath("//link[not(ancestor::pre or ancestor::code)]").each do |favicon|
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
@@ -24,7 +24,7 @@ end
24
24
 
25
25
  class Images < ::HTML::Proofer::Checks::Check
26
26
  def run
27
- @html.xpath('//img[not(ancestor::pre or ancestor::code)]').each do |i|
27
+ @html.css("img").each do |i|
28
28
  img = Image.new i, "image", self
29
29
 
30
30
  next if img.ignore?
@@ -19,10 +19,11 @@ end
19
19
  class Links < ::HTML::Proofer::Checks::Check
20
20
 
21
21
  def run
22
- @html.xpath('//a[not(ancestor::pre or ancestor::code)]', '//link[not(ancestor::pre or ancestor::code)]').each do |l|
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?
@@ -18,7 +18,7 @@ end
18
18
 
19
19
  class Scripts < ::HTML::Proofer::Checks::Check
20
20
  def run
21
- @html.xpath('//script[not(ancestor::pre or ancestor::code)]').each do |s|
21
+ @html.css("script").each do |s|
22
22
  script = Script.new s, "script", self
23
23
 
24
24
  next if script.ignore?
@@ -0,0 +1,13 @@
1
+ <html>
2
+
3
+ <body>
4
+
5
+
6
+ <img src="gpl.png"/>Image.
7
+
8
+
9
+ <p>Blah blah blah. <a href="http://www.kakakakakaakkakakakakakakaakakak.biz.foo.net" /> </p>
10
+
11
+ </body>
12
+
13
+ </html>
@@ -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.3
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-21 00:00:00.000000000 Z
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