-
-
Notifications
You must be signed in to change notification settings - Fork 193
/
favicon.rb
43 lines (36 loc) · 1.23 KB
/
favicon.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# frozen_string_literal: true
module HTMLProofer
class Check
class Favicon < HTMLProofer::Check
def run
found = false
@html.css("link").each do |node|
@favicon = create_element(node)
next if @favicon.ignore?
break if (found = @favicon.node["rel"].split.last.eql?("icon"))
end
return if immediate_redirect?
if found
if @favicon.url.protocol_relative?
add_failure("favicon link #{@favicon.url} is a protocol-relative URL, use explicit https:// instead",
line: @favicon.line, content: @favicon.content)
elsif @favicon.url.remote?
add_to_external_urls(@favicon.url, @favicon.line)
elsif !@favicon.url.exists?
add_failure("internal favicon #{@favicon.url.raw_attribute} does not exist", line: @favicon.line,
content: @favicon.content)
end
else
add_failure("no favicon provided")
end
end
private
# allow any instant-redirect meta tag
def immediate_redirect?
@html.xpath("//meta[@http-equiv='refresh']").attribute("content").value.start_with?("0;")
rescue StandardError
false
end
end
end
end