loofah 0.4.2 → 2.25.0

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.
Files changed (51) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +604 -0
  3. data/MIT-LICENSE.txt +3 -1
  4. data/README.md +410 -0
  5. data/SECURITY.md +18 -0
  6. data/lib/loofah/concerns.rb +207 -0
  7. data/lib/loofah/elements.rb +98 -0
  8. data/lib/loofah/helpers.rb +91 -4
  9. data/lib/loofah/html4/document.rb +17 -0
  10. data/lib/loofah/html4/document_fragment.rb +15 -0
  11. data/lib/loofah/html5/document.rb +17 -0
  12. data/lib/loofah/html5/document_fragment.rb +15 -0
  13. data/lib/loofah/html5/libxml2_workarounds.rb +28 -0
  14. data/lib/loofah/html5/safelist.rb +1058 -0
  15. data/lib/loofah/html5/scrub.rb +211 -40
  16. data/lib/loofah/metahelpers.rb +18 -0
  17. data/lib/loofah/scrubber.rb +31 -13
  18. data/lib/loofah/scrubbers.rb +262 -31
  19. data/lib/loofah/version.rb +6 -0
  20. data/lib/loofah/xml/document.rb +2 -0
  21. data/lib/loofah/xml/document_fragment.rb +6 -9
  22. data/lib/loofah.rb +131 -52
  23. metadata +79 -158
  24. data/CHANGELOG.rdoc +0 -92
  25. data/DEPRECATED.rdoc +0 -12
  26. data/Manifest.txt +0 -34
  27. data/README.rdoc +0 -330
  28. data/Rakefile +0 -61
  29. data/TODO.rdoc +0 -4
  30. data/benchmark/benchmark.rb +0 -149
  31. data/benchmark/fragment.html +0 -96
  32. data/benchmark/helper.rb +0 -73
  33. data/benchmark/www.slashdot.com.html +0 -2560
  34. data/init.rb +0 -1
  35. data/lib/loofah/active_record.rb +0 -62
  36. data/lib/loofah/html/document.rb +0 -22
  37. data/lib/loofah/html/document_fragment.rb +0 -46
  38. data/lib/loofah/html5/whitelist.rb +0 -174
  39. data/lib/loofah/instance_methods.rb +0 -77
  40. data/lib/loofah/xss_foliate.rb +0 -212
  41. data/test/helper.rb +0 -8
  42. data/test/html5/test_sanitizer.rb +0 -248
  43. data/test/test_active_record.rb +0 -146
  44. data/test/test_ad_hoc.rb +0 -272
  45. data/test/test_api.rb +0 -128
  46. data/test/test_helpers.rb +0 -28
  47. data/test/test_scrubber.rb +0 -227
  48. data/test/test_scrubbers.rb +0 -144
  49. data/test/test_xss_foliate.rb +0 -171
  50. data.tar.gz.sig +0 -0
  51. metadata.gz.sig +0 -2
data/README.rdoc DELETED
@@ -1,330 +0,0 @@
1
- = Loofah
2
-
3
- * http://loofah.rubyforge.org
4
- * http://rubyforge.org/projects/loofah
5
- * http://github.com/flavorjones/loofah
6
-
7
- == Description
8
-
9
- Loofah is a general library for manipulating HTML/XML documents and
10
- fragments. It's built on top of Nokogiri and libxml2, so it's fast and
11
- has a nice API.
12
-
13
- Loofah excels at HTML sanitization (XSS prevention). It includes some
14
- nice HTML sanitizers, which are based on HTML5lib's whitelist, so it
15
- most likely won't make your codes less secure. (These statements have
16
- not been evaluated by Netexperts.)
17
-
18
- == Features
19
-
20
- * Easily write custom scrubbers for HTML/XML leveraging the sweetness of Nokogiri (and HTML5lib's whitelists).
21
- * Common HTML sanitizing tasks are built-in:
22
- * _Strip_ unsafe tags, leaving behind only the inner text.
23
- * _Prune_ unsafe tags and their subtrees, removing all traces that they ever existed.
24
- * _Escape_ unsafe tags and their subtrees, leaving behind lots of <tt>&lt;</tt> and <tt>&gt;</tt> entities.
25
- * _Whitewash_ the markup, removing all attributes and namespaced nodes.
26
- * Common HTML transformation tasks are built-in:
27
- * Add the _nofollow_ attribute to all hyperlinks.
28
- * Format markup as plain text.
29
- * Replace Rails's +strip_tags+ and +sanitize+ helper methods.
30
- * Two ActiveRecord extensions:
31
- * Loofah::XssFoliate, an XssTerminate[http://github.com/look/xss_terminate/tree/master] drop-in replacement, is an *opt-out* sanitizer. By default all models and attributes are sanitized.
32
- * Loofah::ActiveRecordExtension is an *opt-in* sanitizer. You must explicitly declare attributes to be sanitized.
33
-
34
- == Compare and Contrast
35
-
36
- Loofah is one of two known Ruby XSS/sanitization solutions that
37
- guarantees well-formed and valid markup (the other is Sanitize, which
38
- also uses Nokogiri).
39
-
40
- Loofah works fine on XML, XHTML and HTML documents.
41
-
42
- Also, it's pretty fast. Here is a benchmark comparing Loofah to other
43
- commonly-used libraries (ActionView, Sanitize, HTML5lib and HTMLfilter):
44
-
45
- * http://gist.github.com/170193
46
-
47
- Lastly, Loofah is extensible. It's super-easy to write your own custom
48
- scrubbers for whatever document manipulation you need. You don't like
49
- the built-in scrubbers? Build your own, like a boss.
50
-
51
- == The Basics
52
-
53
- Loofah wraps Nokogiri[http://nokogiri.org] in a loving
54
- embrace. Nokogiri[http://nokogiri.org] is an excellent HTML/XML
55
- parser. If you don't know how Nokogiri[http://nokogiri.org] works, you
56
- might want to pause for a moment and go check it out. I'll wait.
57
-
58
- Loofah presents the following classes:
59
-
60
- * Loofah::HTML::Document and Loofah::HTML::DocumentFragment
61
- * Loofah::XML::Document and Loofah::XML::DocumentFragment
62
- * Loofah::Scrubber
63
-
64
- The documents and fragments are subclasses of the similar Nokogiri classes.
65
-
66
- The Scrubber represents the document manipulation, either by wrapping
67
- a block,
68
-
69
- span2div = Loofah::Scrubber.new do |node|
70
- node.name = "div" if node.name == "span"
71
- end
72
-
73
- or by implementing a method.
74
-
75
- === Side Note: Fragments vs Documents
76
-
77
- Generally speaking, unless you expect to have a DOCTYPE and a single
78
- root node, you don't have a *document*, you have a *fragment*. For
79
- HTML, another rule of thumb is that *documents* have \&lt;html\&gt;
80
- and \&lt;body\&gt; tags, and *fragments* usually do not.
81
-
82
- HTML fragments should be parsed with Loofah.fragment. Loofah won't
83
- wrap the result in +html+ and +body+ tags, won't add a DOCTYPE
84
- declaration, and will ignore +head+ elements.
85
-
86
- XML fragments should be parsed with Loofah.xml_fragment. Loofah won't
87
- add a DOCTYPE declaration and will allow multiple root nodes.
88
-
89
- HTML documents should be parsed with Loofah.document, which will add
90
- the DOCTYPE declaration, and properly handle +head+ and +body+
91
- elements.
92
-
93
- XML documents should be parsed with Loofah.xml_document. Loofah will
94
- make sure there's a DOCTYPE declaration and a single root node.
95
-
96
- === Loofah::HTML::Document and Loofah::HTML::DocumentFragment
97
-
98
- These classes are subclasses of Nokogiri::HTML::Document and
99
- Nokogiri::HTML::DocumentFragment, so you get all the markup
100
- fixer-uppery and API goodness of Nokogiri.
101
-
102
- The module methods Loofah.document and Loofah.fragment will parse an
103
- HTML document and an HTML fragment, respectively.
104
-
105
- Loofah.document(unsafe_html).is_a?(Nokogiri::HTML::Document) # => true
106
- Loofah.fragment(unsafe_html).is_a?(Nokogiri::HTML::DocumentFragment) # => true
107
-
108
- Loofah injects a +scrub!+ method, which takes either a symbol (for
109
- built-in scrubbers) or a Loofah::Scrubber object (for custom
110
- scrubbers), and modifies the document in-place.
111
-
112
- Loofah overrides +to_s+ to return HTML:
113
-
114
- unsafe_html = "ohai! <div>div is safe</div> <script>but script is not</script>"
115
-
116
- doc = Loofah.fragment(unsafe_html).scrub!(:strip)
117
- doc.to_s # => "ohai! <div>div is safe</div> "
118
-
119
- and +text+ to return plain text:
120
-
121
- doc.text # => "ohai! div is safe "
122
-
123
- === Loofah::XML::Document and Loofah::XML::DocumentFragment
124
-
125
- These classes are subclasses of Nokogiri::XML::Document and
126
- Nokogiri::XML::DocumentFragment, so you get all the markup
127
- fixer-uppery and API goodness of Nokogiri.
128
-
129
- The module methods Loofah.xml_document and Loofah.xml_fragment will
130
- parse an XML document and an XML fragment, respectively.
131
-
132
- Loofah.xml_document(bad_xml).is_a?(Nokogiri::XML::Document) # => true
133
- Loofah.xml_fragment(bad_xml).is_a?(Nokogiri::XML::DocumentFragment) # => true
134
-
135
- === Nodes and NodeSets
136
-
137
- Nokogiri::XML::Node and Nokogiri::XML::NodeSet also get a +scrub!+
138
- method, which makes it easy to scrub subtrees.
139
-
140
- The following code will apply the +employee_scrubber+ only to the
141
- +employee+ nodes (and their subtrees) in the document:
142
-
143
- Loofah.xml_document(bad_xml).xpath("//employee").scrub!(employee_scrubber)
144
-
145
- And this code will only scrub the first +employee+ node and its subtree:
146
-
147
- Loofah.xml_document(bad_xml).at_xpath("//employee").scrub!(employee_scrubber)
148
-
149
- === Loofah::Scrubber
150
-
151
- A Scrubber wraps up a block (or method) that is run on a document node:
152
-
153
- # change all <span> tags to <div> tags
154
- span2div = Loofah::Scrubber.new do |node|
155
- node.name = "div" if node.name == "span"
156
- end
157
-
158
- This can then be run on a document:
159
-
160
- Loofah.fragment("<span>foo</span><p>bar</p>").scrub!(span2div).to_s
161
- # => "<div>foo</div><p>bar</p>"
162
-
163
- Scrubbers can be run on a document in either a top-down traversal (the
164
- default) or bottom-up. Top-down scrubbers can optionally return
165
- Scrubber::STOP to terminate the traversal of a subtree. Read below and
166
- in the Loofah::Scrubber class for more detailed usage.
167
-
168
- Here's an XML example:
169
-
170
- # remove all <employee> tags that have a "deceased" attribute set to true
171
- bring_out_your_dead = Loofah::Scrubber.new do |node|
172
- if node.name == "employee" and node["deceased"] == "true"
173
- node.remove
174
- Loofah::Scrubber::STOP # don't bother with the rest of the subtree
175
- end
176
- end
177
- Loofah.xml_document(File.read('plague.xml')).scrub!(bring_out_your_dead)
178
-
179
- === Built-In HTML Scrubbers
180
-
181
- Loofah comes with a set of sanitizing scrubbers that use HTML5lib's
182
- whitelist algorithm:
183
-
184
- doc.scrub!(:strip) # replaces unknown/unsafe tags with their inner text
185
- doc.scrub!(:prune) # removes unknown/unsafe tags and their children
186
- doc.scrub!(:escape) # escapes unknown/unsafe tags, like this: &lt;script&gt;
187
- doc.scrub!(:whitewash) # removes unknown/unsafe/namespaced tags and their children,
188
- # and strips all node attributes
189
-
190
- Loofah also comes with some common transformation tasks:
191
-
192
- doc.scrub!(:nofollow) # adds rel="nofollow" attribute to links
193
-
194
- See Loofah::Scrubbers for more details and example usage.
195
-
196
- === Chaining Scrubbers
197
-
198
- You can chain scrubbers:
199
-
200
- Loofah.fragment("<span>hello</span> <script>alert('OHAI')</script>") \
201
- .scrub!(:prune) \
202
- .scrub!(span2div).to_s
203
- # => "<div>hello</div> "
204
-
205
- === Shorthand
206
-
207
- The class methods Loofah.scrub_fragment and Loofah.scrub_document are
208
- shorthand.
209
-
210
- Loofah.scrub_fragment(unsafe_html, :prune)
211
- Loofah.scrub_document(unsafe_html, :prune)
212
- Loofah.scrub_xml_fragment(bad_xml, custom_scrubber)
213
- Loofah.scrub_xml_document(bad_xml, custom_scrubber)
214
-
215
- are the same thing as (and arguably semantically clearer than):
216
-
217
- Loofah.fragment(unsafe_html).scrub!(:prune)
218
- Loofah.document(unsafe_html).scrub!(:prune)
219
- Loofah.xml_fragment(bad_xml).scrub!(custom_scrubber)
220
- Loofah.xml_document(bad_xml).scrub!(custom_scrubber)
221
-
222
- === ActiveRecord Extension \#1: Opt-In
223
-
224
- See Loofah::ActiveRecordExtension for full documentation. The methods
225
- mixed into ActiveRecord are:
226
-
227
- * Loofah::ActiveRecordExtension.html_document
228
- * Loofah::ActiveRecordExtension.html_fragment
229
-
230
- which are used to declare how specific string and text attributes
231
- should be scrubbed at +before_validation+.
232
-
233
- # app/model/post.rb
234
- class Post < ActiveRecord::Base
235
- html_fragment :body, :scrub => :prune # scrubs 'body' at before_validation
236
- end
237
-
238
- === ActiveRecord Extension \#2: Opt-Out
239
-
240
- See Loofah::XssFoliate::ClassMethods for more documentation. The methods mixed into ActiveRecord are:
241
-
242
- * Loofah::XssFoliate::ClassMethods.xss_foliate
243
- * Loofah::XssFoliate::ClassMethods.xss_foliated?
244
-
245
- which are used to declare how specific string and text attributes
246
- should be scrubbed at +before_validation+.
247
-
248
- Attributes are stripped by default, unless another scrubber is
249
- specified or the attribute is present in an +:except+ clause.
250
-
251
- === View Helpers
252
-
253
- Loofah has two "view helpers": Loofah::Helpers.sanitize and
254
- Loofah::Helpers.strip_tags, both of which are drop-in replacements for
255
- the ActionView helpers of the same name.
256
-
257
- == Requirements
258
-
259
- * Nokogiri >= 1.3.3
260
- * Rails 2.3, 2.2, 2.1, 2.0 or 1.2 (if you're using the ActiveRecord extensions)
261
-
262
- == Installation
263
-
264
- Unsurprisingly:
265
-
266
- * gem install loofah
267
-
268
- == Support
269
-
270
- The bug tracker is available here:
271
-
272
- * http://github.com/flavorjones/loofah/issues
273
-
274
- And the mailing list is on librelist:
275
-
276
- * loofah@librelist.com / http://librelist.com
277
-
278
- And the IRC channel is \#loofah on freenode.
279
-
280
- == Related Links
281
-
282
- * Nokogiri: http://nokogiri.org
283
- * libxml2: http://xmlsoft.org
284
- * html5lib: http://code.google.com/p/html5lib
285
- * XssTerminate: http://github.com/look/xss_terminate/tree/master
286
-
287
- == Authors
288
-
289
- * {Mike Dalessio}[mailto:mike.dalessio@gmail.com] (@flavorjones)
290
- * {Bryan Helmkamp}[mailto:bryan@brynary.com]
291
-
292
- Featuring code contributed by:
293
-
294
- * Aaron Patterson
295
- * John Barnette
296
- * Josh Owens
297
- * Paul Dix
298
- * Josh Nichols
299
- * Luke Melia
300
-
301
- And a big shout-out to Corey Innis for the name, and feedback on the API.
302
-
303
- == Historical Note
304
-
305
- This library was formerly known as Dryopteris, which was a very bad
306
- name that nobody could spell properly.
307
-
308
- == License
309
-
310
- The MIT License
311
-
312
- Copyright (c) 2009 Mike Dalessio, Bryan Helmkamp
313
-
314
- Permission is hereby granted, free of charge, to any person obtaining a copy
315
- of this software and associated documentation files (the "Software"), to deal
316
- in the Software without restriction, including without limitation the rights
317
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
318
- copies of the Software, and to permit persons to whom the Software is
319
- furnished to do so, subject to the following conditions:
320
-
321
- The above copyright notice and this permission notice shall be included in
322
- all copies or substantial portions of the Software.
323
-
324
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
325
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
326
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
327
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
328
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
329
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
330
- THE SOFTWARE.
data/Rakefile DELETED
@@ -1,61 +0,0 @@
1
- require 'rubygems'
2
- gem 'hoe', '>= 2.3.0'
3
- require 'hoe'
4
-
5
- Hoe.plugin :git
6
-
7
- Hoe.spec "loofah" do
8
- developer "Mike Dalessio", "mike.dalessio@gmail.com"
9
- developer "Bryan Helmkamp", "bryan@brynary.com"
10
-
11
- self.extra_rdoc_files = FileList["*.rdoc"]
12
- self.history_file = "CHANGELOG.rdoc"
13
- self.readme_file = "README.rdoc"
14
-
15
- extra_deps << ["nokogiri", ">= 1.3.3"]
16
- extra_dev_deps << ["mocha", ">=0.9"]
17
- extra_dev_deps << ["thoughtbot-shoulda", ">=2.10"]
18
- extra_dev_deps << ["acts_as_fu", ">=0.0.5"]
19
-
20
- # note: .hoerc should have the following line to omit rails tests and tmp
21
- # exclude: !ruby/regexp /\/tmp\/|\/rails_tests\/|CVS|TAGS|\.(svn|git|DS_Store)/
22
- end
23
-
24
- if File.exist?("rails_test/Rakefile")
25
- load "rails_test/Rakefile"
26
- else
27
- task :test do
28
- puts "----------"
29
- puts "-- NOTE: An additional Rails regression test suite is available in source repository"
30
- puts "----------"
31
- end
32
- end
33
-
34
- task :redocs => :fix_css
35
- task :docs => :fix_css
36
- task :fix_css do
37
- better_css = <<-EOT
38
- .method-description pre {
39
- margin : 1em 0 ;
40
- }
41
-
42
- .method-description ul {
43
- padding : .5em 0 .5em 2em ;
44
- }
45
-
46
- .method-description p {
47
- margin-top : .5em ;
48
- }
49
-
50
- #main ul, div#documentation ul {
51
- list-style-type : disc ! IMPORTANT ;
52
- list-style-position : inside ! IMPORTANT ;
53
- }
54
-
55
- h2 + ul {
56
- margin-top : 1em;
57
- }
58
- EOT
59
- puts "* fixing css"
60
- File.open("doc/rdoc.css", "a") { |f| f.write better_css }
61
- end
data/TODO.rdoc DELETED
@@ -1,4 +0,0 @@
1
- = TODO
2
-
3
- * Allow a <tt>text</tt> option to insert nice newlines after headers and block elements.
4
- * <tt>to_markdown<tt>
@@ -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 }
@@ -1,96 +0,0 @@
1
- <div id="top_parent"></div>
2
-
3
- <div id="jump">
4
- <a href="#main-articles">Stories</a>
5
- <br>
6
- <a href="#blocks">Slash Boxes</a>
7
- <br>
8
- <a href="#comments">Comments</a>
9
- </div>
10
- <a name="topothepage"></a>
11
- <div id="doc3" class="yui-t6 index2 mainpage ac ">
12
- <div id="hd" >
13
- <div id="logo" >
14
-
15
-
16
-
17
- <h1><a href="//slashdot.org"><span>Slashdot</span></a></h1>
18
- <div id="slogan"><h2>News for nerds, stuff that matters</h2></div>
19
- </div>
20
- <a href="#articles" class="hidden">Jump to articles</a>
21
- <div class="nav">
22
- <ul>
23
-
24
-
25
-
26
- <li><a href="//slashdot.org/submit.pl" title="Submit a story to Slashdot">Submit Story</a></li>
27
- <li><a href="//slashdot.org/help" title="Frequently asked questions on Slashdot">Help</a></li>
28
- <li><a href="//slashdot.org/login.pl" onclick="show_login_box(); return false;">Log In</a></li>
29
-
30
- </ul>
31
- </div>
32
-
33
-
34
-
35
-
36
-
37
- <div id="fh_picker_search" style="display: block;">
38
- <form method="get" action="//slashdot.org/index2.pl">
39
- <fieldset class="mode-filter mode-anon">
40
- <legend>Search</legend>
41
-
42
-
43
- <input class="query" type="text" name="fhfilter" value="" id="searchquery"> <input type="button" class="setfhfilter" value="Filter" id="viewsearch" style="display:none"> <input type="submit" class="setsearchfilter" value="Search" id="fhsearch" style="display:none">
44
- <noscript><input type="submit" class="setsearchfilter" value="Search"></noscript>
45
-
46
- <script type="text/javascript">
47
- var slash_search;
48
- $(function(){
49
- if (has_hose()) {
50
- var $search_text = $any('searchquery'),
51
- $panel = $search_text.closest('fieldset');
52
- $search_buttons = $('#viewsearch,#fhsearch'),
53
- ws = /\s+/;
54
-
55
-
56
-
57
- // The search buttons set the firehose option named by their class.
58
- $search_buttons.
59
- click(function(){
60
- var which=this.className;
61
- $search_text.each(function(){
62
- firehose_set_options(which, this.value);
63
- });
64
- return false;
65
- });
66
-
67
- // Provide a globally available function that does whatever clicking the search button would do.
68
- slash_search = function( query ){
69
- query!==undefined && $search_text.val(query);
70
- $search_buttons.filter(':visible:first').click();
71
- };
72
-
73
- $search_text.
74
- keydown(function( e ){ // ESCAPE restores the filter in-effect.
75
- if ( e.which == $.ui.keyCode.ESCAPE ) {
76
- $search_text.val(firehose_settings.fhfilter||'');
77
- return true;
78
- }
79
- if ( e.which == $.ui.keyCode.ENTER ) {
80
- slash_search();
81
- return false;
82
- }
83
- });
84
-
85
- $(document).
86
- bind('firehose-setting-setfhfilter firehose-setting-setsearchfilter', function( e, new_query ){
87
- $('fieldset input[type=text]').each(function(){
88
- $(this).blur().val(new_query);
89
- });
90
- }).
91
- bind('set-options.firehose', function( e, data ){
92
- data.select_section && $panel.toggleClass('mode-filter', data.id!=='unsaved');
93
- });
94
- }
95
- });
96
- </script>