html_validation 1.1.4 → 1.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/html_validation/html_validation_result.rb +20 -20
- data/lib/html_validation/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5922a978e4acaf0b7f437d4c42a77f23d2b02aab
|
4
|
+
data.tar.gz: e3d9a002a264c181e69668d6817d5a2631823d53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6e9a96483cac87c9c865daf501e42db8a7bea659df29b16da948c1abb40489a412f6d0e361586fbf2fd20405f84273774d35f009f7c722fcb5fa9e12372ddbc
|
7
|
+
data.tar.gz: 2c23cab2a04de790e4c9e6f872e7185a0a9fef2930e97cebfe5a89458aba7dc2faa710815a57fa720a0e56f1835c217031d3492569e690de7723ac93facfc6b9
|
@@ -14,12 +14,12 @@ class HTMLValidationResult
|
|
14
14
|
|
15
15
|
# options ex: options[:tidy_opts] = ['--show-warnings false']
|
16
16
|
def initialize(resource, html, datapath, tidy_flags = [], options = {})
|
17
|
-
@resource
|
18
|
-
@html
|
19
|
-
@exceptions
|
20
|
-
@datapath
|
21
|
-
@tidy_flags
|
22
|
-
@options
|
17
|
+
@resource = resource
|
18
|
+
@html = html
|
19
|
+
@exceptions = ''
|
20
|
+
@datapath = datapath
|
21
|
+
@tidy_flags = (HTMLValidation.default_tidy_flags + tidy_flags).uniq
|
22
|
+
@options = options
|
23
23
|
valid?
|
24
24
|
end
|
25
25
|
|
@@ -32,9 +32,9 @@ class HTMLValidationResult
|
|
32
32
|
|
33
33
|
# takes a .url and loads the data into this object
|
34
34
|
def self.load_from_files(filepath)
|
35
|
-
resource
|
36
|
-
html
|
37
|
-
|
35
|
+
resource = File.open("#{filepath}.resource.txt", 'r').read
|
36
|
+
html = File.open("#{filepath}.html.txt", 'r').read
|
37
|
+
HTMLValidationResult.new(resource, html, filepath)
|
38
38
|
end
|
39
39
|
|
40
40
|
# Validates an html string using html tidy. If there are no warnings or exceptions, or
|
@@ -54,7 +54,7 @@ class HTMLValidationResult
|
|
54
54
|
# string is identical, valid? will return true. Note that #exceptions will still list the
|
55
55
|
# exception string, though, even if it is an accepted exception string.
|
56
56
|
def accept!
|
57
|
-
File.open(data_path("accepted"), 'w') {|f| f.write(@exceptions)
|
57
|
+
File.open(data_path("accepted"), 'w') {|f| f.write(@exceptions)}
|
58
58
|
end
|
59
59
|
|
60
60
|
def reject!
|
@@ -82,15 +82,15 @@ class HTMLValidationResult
|
|
82
82
|
end
|
83
83
|
|
84
84
|
def save_html_and_exceptions
|
85
|
-
File.open(data_path("html"), 'w')
|
86
|
-
File.open(data_path("resource"), 'w')
|
87
|
-
File.open(data_path("exceptions"), 'w') {|f| f.write(@exceptions)
|
85
|
+
File.open(data_path("html"), 'w') {|f| f.write(@html)}
|
86
|
+
File.open(data_path("resource"), 'w') {|f| f.write(@resource)}
|
87
|
+
File.open(data_path("exceptions"), 'w') {|f| f.write(@exceptions)}
|
88
88
|
end
|
89
89
|
|
90
|
-
|
90
|
+
# have we previously accepted this exact string for this path?
|
91
91
|
def accepted?(exception_str)
|
92
92
|
exception_str = filter(exception_str)
|
93
|
-
File.exists?(data_path('accepted')) ? filter(File.open(data_path('accepted'),"r").read) == exception_str : false
|
93
|
+
File.exists?(data_path('accepted')) ? filter(File.open(data_path('accepted'), "r").read) == exception_str : false
|
94
94
|
end
|
95
95
|
|
96
96
|
# Line numbers of exceptions are likely to change with any minor edit, so our validation
|
@@ -98,15 +98,15 @@ class HTMLValidationResult
|
|
98
98
|
# if the errors change position in the file (up or down b/c you add or remove code),
|
99
99
|
# accepted exception strings will remain valid.
|
100
100
|
def filter(str)
|
101
|
-
|
102
|
-
|
101
|
+
str = str.gsub(/^line.*trimming empty.*\n/, '') # the messages about empty are overzealous, and not invalid
|
102
|
+
str = str.gsub(/^line.*proprietary.*\n/, '') if options[:ignore_proprietary] # if you use IE only attributes like wrap, or spellcheck or things not in standard
|
103
103
|
str = str.gsub(/^line.*(?:Error|Warning):.*<\/?(?:#{options[:ignored_tag_errors].join('|')})>.*\n/, '') if options[:ignored_tag_errors] && options[:ignored_tag_errors].any?
|
104
104
|
str = str.gsub(/^line.*(?:Error|Warning):.* attribute \"(?:#{options[:ignored_attribute_errors].join('|')})\".*\n/, '') if options[:ignored_attribute_errors] && options[:ignored_attribute_errors].any?
|
105
105
|
if options[:ignored_errors] && options[:ignored_errors].any? && str.gsub(/^line.*(?:Error|Warning):/, '') =~ ignored_errors_regex
|
106
|
-
str = str.gsub(Regexp.new(/^line.*(?:Error|Warning):/.source + '.*' + ignored_errors_regex.source + '.*'
|
106
|
+
str = str.gsub(Regexp.new(/^line.*(?:Error|Warning):/.source + '.*' + ignored_errors_regex.source + '.*' + /\n/.source), '')
|
107
107
|
end
|
108
108
|
str.gsub(/line [0-9]+ column [0-9]+ -/, '')
|
109
|
-
|
109
|
+
# /line [0-9]+ column [0-9]+ - / + =~ "line 1 column 1 - Warning: missing <!DOCTYPE> declaration"
|
110
110
|
end
|
111
111
|
|
112
112
|
def ignored_errors_regex
|
@@ -115,7 +115,7 @@ class HTMLValidationResult
|
|
115
115
|
|
116
116
|
def validate
|
117
117
|
stdin, stdout, stderr = Open3.popen3(tidy_command)
|
118
|
-
stdin.puts @html
|
118
|
+
stdin.puts @html.encode!("UTF-8", invalid: :replace, undef: :replace).force_encoding("utf-8")
|
119
119
|
stdin.close
|
120
120
|
stdout.close
|
121
121
|
result = stderr.read
|