loofah 2.3.1 → 2.8.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of loofah might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/CHANGELOG.md +91 -40
- data/README.md +7 -4
- data/lib/loofah.rb +33 -16
- data/lib/loofah/elements.rb +74 -73
- data/lib/loofah/helpers.rb +5 -4
- data/lib/loofah/html/document.rb +1 -0
- data/lib/loofah/html/document_fragment.rb +4 -2
- data/lib/loofah/html5/libxml2_workarounds.rb +8 -7
- data/lib/loofah/html5/safelist.rb +23 -0
- data/lib/loofah/html5/scrub.rb +21 -21
- data/lib/loofah/instance_methods.rb +5 -3
- data/lib/loofah/metahelpers.rb +2 -1
- data/lib/loofah/scrubber.rb +8 -7
- data/lib/loofah/scrubbers.rb +11 -10
- data/lib/loofah/version.rb +5 -0
- data/lib/loofah/xml/document.rb +1 -0
- data/lib/loofah/xml/document_fragment.rb +2 -1
- metadata +27 -93
- data/.gemtest +0 -0
- data/Gemfile +0 -22
- data/Manifest.txt +0 -41
- data/Rakefile +0 -81
- data/benchmark/benchmark.rb +0 -149
- data/benchmark/fragment.html +0 -96
- data/benchmark/helper.rb +0 -73
- data/benchmark/www.slashdot.com.html +0 -2560
- data/test/assets/msword.html +0 -63
- data/test/assets/testdata_sanitizer_tests1.dat +0 -502
- data/test/helper.rb +0 -18
- data/test/html5/test_sanitizer.rb +0 -401
- data/test/html5/test_scrub.rb +0 -10
- data/test/integration/test_ad_hoc.rb +0 -220
- data/test/integration/test_helpers.rb +0 -43
- data/test/integration/test_html.rb +0 -72
- data/test/integration/test_scrubbers.rb +0 -400
- data/test/integration/test_xml.rb +0 -55
- data/test/unit/test_api.rb +0 -142
- data/test/unit/test_encoding.rb +0 -20
- data/test/unit/test_helpers.rb +0 -62
- data/test/unit/test_scrubber.rb +0 -229
- data/test/unit/test_scrubbers.rb +0 -14
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loofah
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mike Dalessio
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-11-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: nokogiri
|
@@ -45,28 +45,28 @@ dependencies:
|
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
48
|
+
version: '13.0'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: '
|
55
|
+
version: '13.0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: minitest
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
60
|
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '
|
62
|
+
version: '5.14'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: '
|
69
|
+
version: '5.14'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rr
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
@@ -87,84 +87,42 @@ dependencies:
|
|
87
87
|
requirements:
|
88
88
|
- - "~>"
|
89
89
|
- !ruby/object:Gem::Version
|
90
|
-
version: 2.2
|
91
|
-
type: :development
|
92
|
-
prerelease: false
|
93
|
-
version_requirements: !ruby/object:Gem::Requirement
|
94
|
-
requirements:
|
95
|
-
- - "~>"
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: 2.2.0
|
98
|
-
- !ruby/object:Gem::Dependency
|
99
|
-
name: hoe-gemspec
|
100
|
-
requirement: !ruby/object:Gem::Requirement
|
101
|
-
requirements:
|
102
|
-
- - "~>"
|
103
|
-
- !ruby/object:Gem::Version
|
104
|
-
version: '1.0'
|
105
|
-
type: :development
|
106
|
-
prerelease: false
|
107
|
-
version_requirements: !ruby/object:Gem::Requirement
|
108
|
-
requirements:
|
109
|
-
- - "~>"
|
110
|
-
- !ruby/object:Gem::Version
|
111
|
-
version: '1.0'
|
112
|
-
- !ruby/object:Gem::Dependency
|
113
|
-
name: hoe-debugging
|
114
|
-
requirement: !ruby/object:Gem::Requirement
|
115
|
-
requirements:
|
116
|
-
- - "~>"
|
117
|
-
- !ruby/object:Gem::Version
|
118
|
-
version: '2.0'
|
90
|
+
version: '2.2'
|
119
91
|
type: :development
|
120
92
|
prerelease: false
|
121
93
|
version_requirements: !ruby/object:Gem::Requirement
|
122
94
|
requirements:
|
123
95
|
- - "~>"
|
124
96
|
- !ruby/object:Gem::Version
|
125
|
-
version: '2.
|
97
|
+
version: '2.2'
|
126
98
|
- !ruby/object:Gem::Dependency
|
127
|
-
name:
|
99
|
+
name: concourse
|
128
100
|
requirement: !ruby/object:Gem::Requirement
|
129
101
|
requirements:
|
130
102
|
- - "~>"
|
131
103
|
- !ruby/object:Gem::Version
|
132
|
-
version: '
|
104
|
+
version: '0.33'
|
133
105
|
type: :development
|
134
106
|
prerelease: false
|
135
107
|
version_requirements: !ruby/object:Gem::Requirement
|
136
108
|
requirements:
|
137
109
|
- - "~>"
|
138
110
|
- !ruby/object:Gem::Version
|
139
|
-
version: '
|
111
|
+
version: '0.33'
|
140
112
|
- !ruby/object:Gem::Dependency
|
141
|
-
name:
|
113
|
+
name: rubocop
|
142
114
|
requirement: !ruby/object:Gem::Requirement
|
143
115
|
requirements:
|
144
116
|
- - "~>"
|
145
117
|
- !ruby/object:Gem::Version
|
146
|
-
version: '1.
|
118
|
+
version: '1.1'
|
147
119
|
type: :development
|
148
120
|
prerelease: false
|
149
121
|
version_requirements: !ruby/object:Gem::Requirement
|
150
122
|
requirements:
|
151
123
|
- - "~>"
|
152
124
|
- !ruby/object:Gem::Version
|
153
|
-
version: '1.
|
154
|
-
- !ruby/object:Gem::Dependency
|
155
|
-
name: concourse
|
156
|
-
requirement: !ruby/object:Gem::Requirement
|
157
|
-
requirements:
|
158
|
-
- - ">="
|
159
|
-
- !ruby/object:Gem::Version
|
160
|
-
version: 0.26.0
|
161
|
-
type: :development
|
162
|
-
prerelease: false
|
163
|
-
version_requirements: !ruby/object:Gem::Requirement
|
164
|
-
requirements:
|
165
|
-
- - ">="
|
166
|
-
- !ruby/object:Gem::Version
|
167
|
-
version: 0.26.0
|
125
|
+
version: '1.1'
|
168
126
|
- !ruby/object:Gem::Dependency
|
169
127
|
name: rdoc
|
170
128
|
requirement: !ruby/object:Gem::Requirement
|
@@ -186,19 +144,19 @@ dependencies:
|
|
186
144
|
- !ruby/object:Gem::Version
|
187
145
|
version: '7'
|
188
146
|
- !ruby/object:Gem::Dependency
|
189
|
-
name: hoe
|
147
|
+
name: hoe-markdown
|
190
148
|
requirement: !ruby/object:Gem::Requirement
|
191
149
|
requirements:
|
192
150
|
- - "~>"
|
193
151
|
- !ruby/object:Gem::Version
|
194
|
-
version: '3
|
152
|
+
version: '1.3'
|
195
153
|
type: :development
|
196
154
|
prerelease: false
|
197
155
|
version_requirements: !ruby/object:Gem::Requirement
|
198
156
|
requirements:
|
199
157
|
- - "~>"
|
200
158
|
- !ruby/object:Gem::Version
|
201
|
-
version: '3
|
159
|
+
version: '1.3'
|
202
160
|
description: |-
|
203
161
|
Loofah is a general library for manipulating and transforming HTML/XML documents and fragments, built on top of Nokogiri.
|
204
162
|
|
@@ -210,25 +168,12 @@ email:
|
|
210
168
|
- bryan@brynary.com
|
211
169
|
executables: []
|
212
170
|
extensions: []
|
213
|
-
extra_rdoc_files:
|
214
|
-
- CHANGELOG.md
|
215
|
-
- MIT-LICENSE.txt
|
216
|
-
- Manifest.txt
|
217
|
-
- README.md
|
218
|
-
- SECURITY.md
|
171
|
+
extra_rdoc_files: []
|
219
172
|
files:
|
220
|
-
- ".gemtest"
|
221
173
|
- CHANGELOG.md
|
222
|
-
- Gemfile
|
223
174
|
- MIT-LICENSE.txt
|
224
|
-
- Manifest.txt
|
225
175
|
- README.md
|
226
|
-
- Rakefile
|
227
176
|
- SECURITY.md
|
228
|
-
- benchmark/benchmark.rb
|
229
|
-
- benchmark/fragment.html
|
230
|
-
- benchmark/helper.rb
|
231
|
-
- benchmark/www.slashdot.com.html
|
232
177
|
- lib/loofah.rb
|
233
178
|
- lib/loofah/elements.rb
|
234
179
|
- lib/loofah/helpers.rb
|
@@ -241,31 +186,20 @@ files:
|
|
241
186
|
- lib/loofah/metahelpers.rb
|
242
187
|
- lib/loofah/scrubber.rb
|
243
188
|
- lib/loofah/scrubbers.rb
|
189
|
+
- lib/loofah/version.rb
|
244
190
|
- lib/loofah/xml/document.rb
|
245
191
|
- lib/loofah/xml/document_fragment.rb
|
246
|
-
- test/assets/msword.html
|
247
|
-
- test/assets/testdata_sanitizer_tests1.dat
|
248
|
-
- test/helper.rb
|
249
|
-
- test/html5/test_sanitizer.rb
|
250
|
-
- test/html5/test_scrub.rb
|
251
|
-
- test/integration/test_ad_hoc.rb
|
252
|
-
- test/integration/test_helpers.rb
|
253
|
-
- test/integration/test_html.rb
|
254
|
-
- test/integration/test_scrubbers.rb
|
255
|
-
- test/integration/test_xml.rb
|
256
|
-
- test/unit/test_api.rb
|
257
|
-
- test/unit/test_encoding.rb
|
258
|
-
- test/unit/test_helpers.rb
|
259
|
-
- test/unit/test_scrubber.rb
|
260
|
-
- test/unit/test_scrubbers.rb
|
261
192
|
homepage: https://github.com/flavorjones/loofah
|
262
193
|
licenses:
|
263
194
|
- MIT
|
264
|
-
metadata:
|
195
|
+
metadata:
|
196
|
+
homepage_uri: https://github.com/flavorjones/loofah
|
197
|
+
source_code_uri: https://github.com/flavorjones/loofah
|
198
|
+
bug_tracker_uri: https://github.com/flavorjones/loofah/issues
|
199
|
+
changelog_uri: https://github.com/flavorjones/loofah/blob/master/CHANGELOG.md
|
200
|
+
documentation_uri: https://www.rubydoc.info/gems/loofah/
|
265
201
|
post_install_message:
|
266
|
-
rdoc_options:
|
267
|
-
- "--main"
|
268
|
-
- README.md
|
202
|
+
rdoc_options: []
|
269
203
|
require_paths:
|
270
204
|
- lib
|
271
205
|
required_ruby_version: !ruby/object:Gem::Requirement
|
@@ -279,7 +213,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
279
213
|
- !ruby/object:Gem::Version
|
280
214
|
version: '0'
|
281
215
|
requirements: []
|
282
|
-
rubygems_version: 3.
|
216
|
+
rubygems_version: 3.1.4
|
283
217
|
signing_key:
|
284
218
|
specification_version: 4
|
285
219
|
summary: Loofah is a general library for manipulating and transforming HTML/XML documents
|
data/.gemtest
DELETED
File without changes
|
data/Gemfile
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
# -*- ruby -*-
|
2
|
-
|
3
|
-
# DO NOT EDIT THIS FILE. Instead, edit Rakefile, and run `rake bundler:gemfile`.
|
4
|
-
|
5
|
-
source "https://rubygems.org/"
|
6
|
-
|
7
|
-
gem "nokogiri", ">=1.5.9"
|
8
|
-
gem "crass", "~>1.0.2"
|
9
|
-
|
10
|
-
gem "rake", ">=0.8", :group => [:development, :test]
|
11
|
-
gem "minitest", "~>2.2", :group => [:development, :test]
|
12
|
-
gem "rr", "~>1.2.0", :group => [:development, :test]
|
13
|
-
gem "json", ">=0", :group => [:development, :test]
|
14
|
-
gem "hoe-gemspec", ">=0", :group => [:development, :test]
|
15
|
-
gem "hoe-debugging", ">=0", :group => [:development, :test]
|
16
|
-
gem "hoe-bundler", ">=0", :group => [:development, :test]
|
17
|
-
gem "hoe-git", ">=0", :group => [:development, :test]
|
18
|
-
gem "concourse", ">=0.26.0", :group => [:development, :test]
|
19
|
-
gem "rdoc", ">=4.0", "<7", :group => [:development, :test]
|
20
|
-
gem "hoe", "~>3.17", :group => [:development, :test]
|
21
|
-
|
22
|
-
# vim: syntax=ruby
|
data/Manifest.txt
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
.gemtest
|
2
|
-
CHANGELOG.md
|
3
|
-
Gemfile
|
4
|
-
MIT-LICENSE.txt
|
5
|
-
Manifest.txt
|
6
|
-
README.md
|
7
|
-
Rakefile
|
8
|
-
SECURITY.md
|
9
|
-
benchmark/benchmark.rb
|
10
|
-
benchmark/fragment.html
|
11
|
-
benchmark/helper.rb
|
12
|
-
benchmark/www.slashdot.com.html
|
13
|
-
lib/loofah.rb
|
14
|
-
lib/loofah/elements.rb
|
15
|
-
lib/loofah/helpers.rb
|
16
|
-
lib/loofah/html/document.rb
|
17
|
-
lib/loofah/html/document_fragment.rb
|
18
|
-
lib/loofah/html5/libxml2_workarounds.rb
|
19
|
-
lib/loofah/html5/safelist.rb
|
20
|
-
lib/loofah/html5/scrub.rb
|
21
|
-
lib/loofah/instance_methods.rb
|
22
|
-
lib/loofah/metahelpers.rb
|
23
|
-
lib/loofah/scrubber.rb
|
24
|
-
lib/loofah/scrubbers.rb
|
25
|
-
lib/loofah/xml/document.rb
|
26
|
-
lib/loofah/xml/document_fragment.rb
|
27
|
-
test/assets/msword.html
|
28
|
-
test/assets/testdata_sanitizer_tests1.dat
|
29
|
-
test/helper.rb
|
30
|
-
test/html5/test_sanitizer.rb
|
31
|
-
test/html5/test_scrub.rb
|
32
|
-
test/integration/test_ad_hoc.rb
|
33
|
-
test/integration/test_helpers.rb
|
34
|
-
test/integration/test_html.rb
|
35
|
-
test/integration/test_scrubbers.rb
|
36
|
-
test/integration/test_xml.rb
|
37
|
-
test/unit/test_api.rb
|
38
|
-
test/unit/test_encoding.rb
|
39
|
-
test/unit/test_helpers.rb
|
40
|
-
test/unit/test_scrubber.rb
|
41
|
-
test/unit/test_scrubbers.rb
|
data/Rakefile
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "hoe"
|
3
|
-
require "concourse"
|
4
|
-
|
5
|
-
Hoe.plugin :git
|
6
|
-
Hoe.plugin :gemspec
|
7
|
-
Hoe.plugin :bundler
|
8
|
-
Hoe.plugin :debugging
|
9
|
-
|
10
|
-
Hoe.spec "loofah" do
|
11
|
-
developer "Mike Dalessio", "mike.dalessio@gmail.com"
|
12
|
-
developer "Bryan Helmkamp", "bryan@brynary.com"
|
13
|
-
|
14
|
-
self.extra_rdoc_files = FileList["*.md"]
|
15
|
-
self.history_file = "CHANGELOG.md"
|
16
|
-
self.readme_file = "README.md"
|
17
|
-
self.license "MIT"
|
18
|
-
|
19
|
-
extra_deps << ["nokogiri", ">=1.5.9"]
|
20
|
-
extra_deps << ["crass", "~> 1.0.2"]
|
21
|
-
|
22
|
-
extra_dev_deps << ["rake", "~> 12.3"]
|
23
|
-
extra_dev_deps << ["minitest", "~>2.2"]
|
24
|
-
extra_dev_deps << ["rr", "~>1.2.0"]
|
25
|
-
extra_dev_deps << ["json", "~> 2.2.0"]
|
26
|
-
extra_dev_deps << ["hoe-gemspec", "~> 1.0"]
|
27
|
-
extra_dev_deps << ["hoe-debugging", "~> 2.0"]
|
28
|
-
extra_dev_deps << ["hoe-bundler", "~> 1.5"]
|
29
|
-
extra_dev_deps << ["hoe-git", "~> 1.6"]
|
30
|
-
extra_dev_deps << ["concourse", ">=0.26.0"]
|
31
|
-
end
|
32
|
-
|
33
|
-
task :gemspec do
|
34
|
-
system %q(rake debug_gem | grep -v "^\(in " > loofah.gemspec)
|
35
|
-
end
|
36
|
-
|
37
|
-
task :redocs => :fix_css
|
38
|
-
task :docs => :fix_css
|
39
|
-
task :fix_css do
|
40
|
-
better_css = <<-EOT
|
41
|
-
.method-description pre {
|
42
|
-
margin : 1em 0 ;
|
43
|
-
}
|
44
|
-
|
45
|
-
.method-description ul {
|
46
|
-
padding : .5em 0 .5em 2em ;
|
47
|
-
}
|
48
|
-
|
49
|
-
.method-description p {
|
50
|
-
margin-top : .5em ;
|
51
|
-
}
|
52
|
-
|
53
|
-
#main ul, div#documentation ul {
|
54
|
-
list-style-type : disc ! IMPORTANT ;
|
55
|
-
list-style-position : inside ! IMPORTANT ;
|
56
|
-
}
|
57
|
-
|
58
|
-
h2 + ul {
|
59
|
-
margin-top : 1em;
|
60
|
-
}
|
61
|
-
EOT
|
62
|
-
puts "* fixing css"
|
63
|
-
File.open("doc/rdoc.css", "a") { |f| f.write better_css }
|
64
|
-
end
|
65
|
-
|
66
|
-
desc "generate and upload docs to rubyforge"
|
67
|
-
task :doc_upload_to_rubyforge => :docs do
|
68
|
-
Dir.chdir "doc" do
|
69
|
-
system "rsync -avz --delete * rubyforge.org:/var/www/gforge-projects/loofah/loofah"
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
desc "generate safelists from W3C specifications"
|
74
|
-
task :generate_safelists do
|
75
|
-
load "tasks/generate-safelists"
|
76
|
-
end
|
77
|
-
|
78
|
-
Concourse.new("loofah", fly_target: "ci") do |c|
|
79
|
-
c.add_pipeline "loofah", "loofah.yml"
|
80
|
-
c.add_pipeline "loofah-pr", "loofah-pr.yml"
|
81
|
-
end
|
data/benchmark/benchmark.rb
DELETED
@@ -1,149 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
require "#{File.dirname(__FILE__)}/helper.rb"
|
3
|
-
|
4
|
-
def compare_scrub_methods
|
5
|
-
snip = "<div>foo</div><foo>fuxx <b>quux</b></foo><script>i have a chair</script>"
|
6
|
-
puts "starting with:\n#{snip}"
|
7
|
-
puts
|
8
|
-
puts RailsSanitize.new.sanitize(snip) # => Rails.sanitize / scrub!(:prune).to_s
|
9
|
-
puts Loofah::Helpers.sanitize(snip)
|
10
|
-
puts "--"
|
11
|
-
puts RailsSanitize.new.strip_tags(snip) # => Rails.strip_tags / parse().text
|
12
|
-
puts Loofah::Helpers.strip_tags(snip)
|
13
|
-
puts "--"
|
14
|
-
puts Sanitize.clean(snip, Sanitize::Config::RELAXED) # => scrub!(:strip).to_s
|
15
|
-
puts Loofah.scrub_fragment(snip, :strip).to_s
|
16
|
-
puts "--"
|
17
|
-
puts HTML5libSanitize.new.sanitize(snip) # => scrub!(:escape).to_s
|
18
|
-
puts Loofah.scrub_fragment(snip, :escape).to_s
|
19
|
-
puts "--"
|
20
|
-
puts HTMLFilter.new.filter(snip)
|
21
|
-
puts Loofah.scrub_fragment(snip, :strip).to_s
|
22
|
-
puts
|
23
|
-
end
|
24
|
-
|
25
|
-
module TestSet
|
26
|
-
def test_set options={}
|
27
|
-
scale = options[:rehearse] ? 10 : 1
|
28
|
-
puts self.class.name
|
29
|
-
|
30
|
-
n = 100 / scale
|
31
|
-
puts " Large document, #{BIG_FILE.length} bytes (x#{n})"
|
32
|
-
bench BIG_FILE, n, false
|
33
|
-
puts
|
34
|
-
|
35
|
-
n = 1000 / scale
|
36
|
-
puts " Small fragment, #{FRAGMENT.length} bytes (x#{n})"
|
37
|
-
bench FRAGMENT, n, true
|
38
|
-
puts
|
39
|
-
|
40
|
-
n = 10_000 / scale
|
41
|
-
puts " Text snippet, #{SNIPPET.length} bytes (x#{n})"
|
42
|
-
bench SNIPPET, n, true
|
43
|
-
puts
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
class HeadToHead < Measure
|
48
|
-
end
|
49
|
-
|
50
|
-
class HeadToHeadRailsSanitize < Measure
|
51
|
-
include TestSet
|
52
|
-
def bench(content, ntimes, fragment_p)
|
53
|
-
clear_measure
|
54
|
-
|
55
|
-
measure "Loofah::Helpers.sanitize", ntimes do
|
56
|
-
Loofah::Helpers.sanitize content
|
57
|
-
end
|
58
|
-
|
59
|
-
sanitizer = RailsSanitize.new
|
60
|
-
measure "ActionView sanitize", ntimes do
|
61
|
-
sanitizer.sanitize(content)
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
class HeadToHeadRailsStripTags < Measure
|
67
|
-
include TestSet
|
68
|
-
def bench(content, ntimes, fragment_p)
|
69
|
-
clear_measure
|
70
|
-
|
71
|
-
measure "Loofah::Helpers.strip_tags", ntimes do
|
72
|
-
Loofah::Helpers.strip_tags content
|
73
|
-
end
|
74
|
-
|
75
|
-
sanitizer = RailsSanitize.new
|
76
|
-
measure "ActionView strip_tags", ntimes do
|
77
|
-
sanitizer.strip_tags(content)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
class HeadToHeadSanitizerSanitize < Measure
|
83
|
-
include TestSet
|
84
|
-
def bench(content, ntimes, fragment_p)
|
85
|
-
clear_measure
|
86
|
-
|
87
|
-
measure "Loofah :strip", ntimes do
|
88
|
-
if fragment_p
|
89
|
-
Loofah.scrub_fragment(content, :strip).to_s
|
90
|
-
else
|
91
|
-
Loofah.scrub_document(content, :strip).to_s
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
measure "Sanitize.clean", ntimes do
|
96
|
-
Sanitize.clean(content, Sanitize::Config::RELAXED)
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
class HeadToHeadHtml5LibSanitize < Measure
|
102
|
-
include TestSet
|
103
|
-
def bench(content, ntimes, fragment_p)
|
104
|
-
clear_measure
|
105
|
-
|
106
|
-
measure "Loofah :escape", ntimes do
|
107
|
-
if fragment_p
|
108
|
-
Loofah.scrub_fragment(content, :escape).to_s
|
109
|
-
else
|
110
|
-
Loofah.scrub_document(content, :escape).to_s
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
html5_sanitizer = HTML5libSanitize.new
|
115
|
-
measure "HTML5lib.sanitize", ntimes do
|
116
|
-
html5_sanitizer.sanitize(content)
|
117
|
-
end
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
class HeadToHeadHTMLFilter < Measure
|
122
|
-
include TestSet
|
123
|
-
def bench(content, ntimes, fragment_p)
|
124
|
-
clear_measure
|
125
|
-
|
126
|
-
measure "Loofah::Helpers.sanitize", ntimes do
|
127
|
-
Loofah::Helpers.sanitize content
|
128
|
-
end
|
129
|
-
|
130
|
-
sanitizer = HTMLFilter.new
|
131
|
-
measure "HTMLFilter.filter", ntimes do
|
132
|
-
sanitizer.filter(content)
|
133
|
-
end
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
puts "Nokogiri version: #{Nokogiri::VERSION_INFO.inspect}"
|
138
|
-
puts "Loofah version: #{Loofah::VERSION.inspect}"
|
139
|
-
|
140
|
-
benches = []
|
141
|
-
benches << HeadToHeadRailsSanitize.new
|
142
|
-
benches << HeadToHeadRailsStripTags.new
|
143
|
-
benches << HeadToHeadSanitizerSanitize.new
|
144
|
-
benches << HeadToHeadHtml5LibSanitize.new
|
145
|
-
benches << HeadToHeadHTMLFilter.new
|
146
|
-
puts "---------- rehearsal ----------"
|
147
|
-
benches.each { |bench| bench.test_set :rehearse => true }
|
148
|
-
puts "---------- realsies ----------"
|
149
|
-
benches.each { |bench| bench.test_set }
|