loofah 1.0.0 → 1.1.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.

Potentially problematic release.


This version of loofah might be problematic. Click here for more details.

@@ -1,10 +1,10 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helper'))
1
+ require "helper"
2
2
 
3
- class TestXml < Test::Unit::TestCase
3
+ class IntegrationTestXml < Loofah::TestCase
4
4
  context "integration test" do
5
5
  context "xml document" do
6
6
  context "custom scrubber" do
7
- should "act as expected" do
7
+ it "act as expected" do
8
8
  xml = Loofah.xml_document <<-EOXML
9
9
  <root>
10
10
  <employee deceased='true'>Abraham Lincoln</employee>
@@ -30,7 +30,7 @@ class TestXml < Test::Unit::TestCase
30
30
 
31
31
  context "xml fragment" do
32
32
  context "custom scrubber" do
33
- should "act as expected" do
33
+ it "act as expected" do
34
34
  xml = Loofah.xml_fragment <<-EOXML
35
35
  <employee deceased='true'>Abraham Lincoln</employee>
36
36
  <employee deceased='false'>Abe Vigoda</employee>
@@ -1,6 +1,6 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helper'))
1
+ require "helper"
2
2
 
3
- class TestApi < Test::Unit::TestCase
3
+ class UnitTestApi < Loofah::TestCase
4
4
 
5
5
  HTML = "<div>a</div>\n<div>b</div>"
6
6
  XML_FRAGMENT = "<div>a</div>\n<div>b</div>"
@@ -99,12 +99,12 @@ class TestApi < Test::Unit::TestCase
99
99
  node_set.scrub!(:strip)
100
100
  end
101
101
 
102
- should "HTML::DocumentFragment exposes serialize_root" do
102
+ it "HTML::DocumentFragment exposes serialize_root" do
103
103
  doc = Loofah.fragment(HTML)
104
104
  assert_equal HTML, doc.serialize_root.to_html
105
105
  end
106
106
 
107
- should "HTML::Document exposes serialize_root" do
107
+ it "HTML::Document exposes serialize_root" do
108
108
  doc = Loofah.document(HTML)
109
109
  assert_equal HTML, doc.serialize_root.children.to_html
110
110
  end
@@ -0,0 +1,20 @@
1
+ # :coding: utf-8
2
+ require "helper"
3
+
4
+ class UnitTestEncoding < Loofah::TestCase
5
+ def setup
6
+ @utf8_string = "日本語"
7
+ end
8
+
9
+ if String.new.respond_to?(:encoding)
10
+ def test_html_fragment_string_sets_encoding
11
+ escaped = Loofah.scrub_fragment(@utf8_string, :escape).to_s
12
+ assert_equal @utf8_string.encoding, escaped.encoding
13
+ end
14
+
15
+ def test_xml_fragment_string_sets_encoding
16
+ escaped = Loofah.scrub_xml_fragment(@utf8_string, :escape).to_s
17
+ assert_equal @utf8_string.encoding, escaped.encoding
18
+ end
19
+ end
20
+ end
@@ -1,25 +1,25 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helper'))
1
+ require "helper"
2
2
 
3
- class TestHelpers < Test::Unit::TestCase
3
+ class UnitTestHelpers < Loofah::TestCase
4
4
 
5
5
  HTML_STRING = "<div>omgwtfbbq</div>"
6
6
 
7
7
  context "#strip_tags" do
8
- should "invoke Loofah.fragment.text" do
9
- mock_doc = mock
10
- Loofah.expects(:fragment).with(HTML_STRING).returns(mock_doc)
11
- mock_doc.expects(:text)
8
+ it "invoke Loofah.fragment.text" do
9
+ mock_doc = Object.new
10
+ mock(Loofah).fragment(HTML_STRING) { mock_doc }
11
+ mock(mock_doc).text
12
12
 
13
13
  Loofah::Helpers.strip_tags HTML_STRING
14
14
  end
15
15
  end
16
16
 
17
17
  context "#sanitize" do
18
- should "invoke Loofah.scrub_fragment(:strip).to_s" do
19
- mock_doc = mock
20
- Loofah.expects(:fragment).with(HTML_STRING).returns(mock_doc)
21
- mock_doc.expects(:scrub!).with(:strip).returns(mock_doc)
22
- mock_doc.expects(:to_s)
18
+ it "invoke Loofah.scrub_fragment(:strip).to_s" do
19
+ mock_doc = Object.new
20
+ mock(Loofah).fragment(HTML_STRING) { mock_doc }
21
+ mock(mock_doc).scrub!(:strip) { mock_doc }
22
+ mock(mock_doc).to_s
23
23
 
24
24
  Loofah::Helpers.sanitize HTML_STRING
25
25
  end
@@ -1,6 +1,6 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helper'))
1
+ require "helper"
2
2
 
3
- class TestScrubber < Test::Unit::TestCase
3
+ class UnitTestScrubber < Loofah::TestCase
4
4
 
5
5
  FRAGMENT = "<span>hello</span><span>goodbye</span>"
6
6
  FRAGMENT_NODE_COUNT = 4 # span, text, span, text
@@ -10,119 +10,119 @@ class TestScrubber < Test::Unit::TestCase
10
10
  DOCUMENT_NODE_STOP_TOP_DOWN = 1 # html
11
11
 
12
12
  context "receiving a block" do
13
- setup do
13
+ before do
14
14
  @count = 0
15
15
  end
16
16
 
17
17
  context "returning CONTINUE" do
18
- setup do
18
+ before do
19
19
  @scrubber = Loofah::Scrubber.new do |node|
20
20
  @count += 1
21
21
  Loofah::Scrubber::CONTINUE
22
22
  end
23
23
  end
24
24
 
25
- should "operate properly on a fragment" do
25
+ it "operate properly on a fragment" do
26
26
  Loofah.scrub_fragment(FRAGMENT, @scrubber)
27
27
  assert_equal FRAGMENT_NODE_COUNT, @count
28
28
  end
29
29
 
30
- should "operate properly on a document" do
30
+ it "operate properly on a document" do
31
31
  Loofah.scrub_document(DOCUMENT, @scrubber)
32
32
  assert_equal DOCUMENT_NODE_COUNT, @count
33
33
  end
34
34
  end
35
35
 
36
36
  context "returning STOP" do
37
- setup do
37
+ before do
38
38
  @scrubber = Loofah::Scrubber.new do |node|
39
39
  @count += 1
40
40
  Loofah::Scrubber::STOP
41
41
  end
42
42
  end
43
43
 
44
- should "operate as top-down on a fragment" do
44
+ it "operate as top-down on a fragment" do
45
45
  Loofah.scrub_fragment(FRAGMENT, @scrubber)
46
46
  assert_equal FRAGMENT_NODE_STOP_TOP_DOWN, @count
47
47
  end
48
48
 
49
- should "operate as top-down on a document" do
49
+ it "operate as top-down on a document" do
50
50
  Loofah.scrub_document(DOCUMENT, @scrubber)
51
51
  assert_equal DOCUMENT_NODE_STOP_TOP_DOWN, @count
52
52
  end
53
53
  end
54
54
 
55
55
  context "returning neither CONTINUE nor STOP" do
56
- setup do
56
+ before do
57
57
  @scrubber = Loofah::Scrubber.new do |node|
58
58
  @count += 1
59
59
  end
60
60
  end
61
61
 
62
- should "act as if CONTINUE was returned" do
62
+ it "act as if CONTINUE was returned" do
63
63
  Loofah.scrub_fragment(FRAGMENT, @scrubber)
64
64
  assert_equal FRAGMENT_NODE_COUNT, @count
65
65
  end
66
66
  end
67
67
 
68
68
  context "not specifying direction" do
69
- setup do
69
+ before do
70
70
  @scrubber = Loofah::Scrubber.new() do |node|
71
71
  @count += 1
72
72
  Loofah::Scrubber::STOP
73
73
  end
74
74
  end
75
75
 
76
- should "operate as top-down on a fragment" do
76
+ it "operate as top-down on a fragment" do
77
77
  Loofah.scrub_fragment(FRAGMENT, @scrubber)
78
78
  assert_equal FRAGMENT_NODE_STOP_TOP_DOWN, @count
79
79
  end
80
80
 
81
- should "operate as top-down on a document" do
81
+ it "operate as top-down on a document" do
82
82
  Loofah.scrub_document(DOCUMENT, @scrubber)
83
83
  assert_equal DOCUMENT_NODE_STOP_TOP_DOWN, @count
84
84
  end
85
85
  end
86
86
 
87
87
  context "specifying top-down direction" do
88
- setup do
88
+ before do
89
89
  @scrubber = Loofah::Scrubber.new(:direction => :top_down) do |node|
90
90
  @count += 1
91
91
  Loofah::Scrubber::STOP
92
92
  end
93
93
  end
94
94
 
95
- should "operate as top-down on a fragment" do
95
+ it "operate as top-down on a fragment" do
96
96
  Loofah.scrub_fragment(FRAGMENT, @scrubber)
97
97
  assert_equal FRAGMENT_NODE_STOP_TOP_DOWN, @count
98
98
  end
99
99
 
100
- should "operate as top-down on a document" do
100
+ it "operate as top-down on a document" do
101
101
  Loofah.scrub_document(DOCUMENT, @scrubber)
102
102
  assert_equal DOCUMENT_NODE_STOP_TOP_DOWN, @count
103
103
  end
104
104
  end
105
105
 
106
106
  context "specifying bottom-up direction" do
107
- setup do
107
+ before do
108
108
  @scrubber = Loofah::Scrubber.new(:direction => :bottom_up) do |node|
109
109
  @count += 1
110
110
  end
111
111
  end
112
112
 
113
- should "operate as bottom-up on a fragment" do
113
+ it "operate as bottom-up on a fragment" do
114
114
  Loofah.scrub_fragment(FRAGMENT, @scrubber)
115
115
  assert_equal FRAGMENT_NODE_COUNT, @count
116
116
  end
117
117
 
118
- should "operate as bottom-up on a document" do
118
+ it "operate as bottom-up on a document" do
119
119
  Loofah.scrub_document(DOCUMENT, @scrubber)
120
120
  assert_equal DOCUMENT_NODE_COUNT, @count
121
121
  end
122
122
  end
123
123
 
124
124
  context "invalid direction" do
125
- should "raise an exception" do
125
+ it "raise an exception" do
126
126
  assert_raises(ArgumentError) {
127
127
  Loofah::Scrubber.new(:direction => :quux) { }
128
128
  }
@@ -130,13 +130,13 @@ class TestScrubber < Test::Unit::TestCase
130
130
  end
131
131
 
132
132
  context "given a block taking zero arguments" do
133
- setup do
133
+ before do
134
134
  @scrubber = Loofah::Scrubber.new do
135
135
  @count += 1
136
136
  end
137
137
  end
138
138
 
139
- should "work anyway, shrug" do
139
+ it "work anyway, shrug" do
140
140
  Loofah.scrub_fragment(FRAGMENT, @scrubber)
141
141
  assert_equal FRAGMENT_NODE_COUNT, @count
142
142
  end
@@ -144,7 +144,7 @@ class TestScrubber < Test::Unit::TestCase
144
144
  end
145
145
 
146
146
  context "defining a new Scrubber class" do
147
- setup do
147
+ before do
148
148
  @klass = Class.new(Loofah::Scrubber) do
149
149
  attr_accessor :count
150
150
 
@@ -161,51 +161,51 @@ class TestScrubber < Test::Unit::TestCase
161
161
  end
162
162
 
163
163
  context "when not specifying direction" do
164
- setup do
164
+ before do
165
165
  @scrubber = @klass.new
166
166
  assert_nil @scrubber.direction
167
167
  end
168
168
 
169
- should "operate as top-down on a fragment" do
169
+ it "operate as top-down on a fragment" do
170
170
  Loofah.scrub_fragment(FRAGMENT, @scrubber)
171
171
  assert_equal FRAGMENT_NODE_STOP_TOP_DOWN, @scrubber.count
172
172
  end
173
173
 
174
- should "operate as top-down on a document" do
174
+ it "operate as top-down on a document" do
175
175
  Loofah.scrub_document(DOCUMENT, @scrubber)
176
176
  assert_equal DOCUMENT_NODE_STOP_TOP_DOWN, @scrubber.count
177
177
  end
178
178
  end
179
179
 
180
180
  context "when direction is specified as top_down" do
181
- setup do
181
+ before do
182
182
  @scrubber = @klass.new(:top_down)
183
183
  assert_equal :top_down, @scrubber.direction
184
184
  end
185
185
 
186
- should "operate as top-down on a fragment" do
186
+ it "operate as top-down on a fragment" do
187
187
  Loofah.scrub_fragment(FRAGMENT, @scrubber)
188
188
  assert_equal FRAGMENT_NODE_STOP_TOP_DOWN, @scrubber.count
189
189
  end
190
190
 
191
- should "operate as top-down on a document" do
191
+ it "operate as top-down on a document" do
192
192
  Loofah.scrub_document(DOCUMENT, @scrubber)
193
193
  assert_equal DOCUMENT_NODE_STOP_TOP_DOWN, @scrubber.count
194
194
  end
195
195
  end
196
196
 
197
197
  context "when direction is specified as bottom_up" do
198
- setup do
198
+ before do
199
199
  @scrubber = @klass.new(:bottom_up)
200
200
  assert_equal :bottom_up, @scrubber.direction
201
201
  end
202
202
 
203
- should "operate as bottom-up on a fragment" do
203
+ it "operate as bottom-up on a fragment" do
204
204
  Loofah.scrub_fragment(FRAGMENT, @scrubber)
205
205
  assert_equal FRAGMENT_NODE_COUNT, @scrubber.count
206
206
  end
207
207
 
208
- should "operate as bottom-up on a document" do
208
+ it "operate as bottom-up on a document" do
209
209
  Loofah.scrub_document(DOCUMENT, @scrubber)
210
210
  assert_equal DOCUMENT_NODE_COUNT, @scrubber.count
211
211
  end
@@ -213,14 +213,14 @@ class TestScrubber < Test::Unit::TestCase
213
213
  end
214
214
 
215
215
  context "creating a new Scrubber class with no scrub method" do
216
- setup do
216
+ before do
217
217
  @klass = Class.new(Loofah::Scrubber) do
218
218
  def initialize ; end
219
219
  end
220
220
  @scrubber = @klass.new
221
221
  end
222
222
 
223
- should "raise an exception" do
223
+ it "raise an exception" do
224
224
  assert_raises(Loofah::ScrubberNotFound) {
225
225
  Loofah.scrub_fragment(FRAGMENT, @scrubber)
226
226
  }
@@ -1,10 +1,10 @@
1
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'helper'))
1
+ require "helper"
2
2
 
3
- class TestScrubbers < Test::Unit::TestCase
3
+ class UnitTestScrubbers < Loofah::TestCase
4
4
  [ Loofah::HTML::Document, Loofah::HTML::DocumentFragment ].each do |klass|
5
5
  context klass do
6
6
  context "bad scrub method" do
7
- should "raise a ScrubberNotFound exception" do
7
+ it "raise a ScrubberNotFound exception" do
8
8
  doc = klass.parse "<p>foo</p>"
9
9
  assert_raises(Loofah::ScrubberNotFound) { doc.scrub! :frippery }
10
10
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loofah
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
5
- prerelease: false
4
+ hash: 19
5
+ prerelease:
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 0
10
- version: 1.0.0
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Mike Dalessio
@@ -16,102 +16,155 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-10-26 00:00:00 -04:00
19
+ date: 2011-08-08 00:00:00 -04:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
- name: nokogiri
24
23
  prerelease: false
24
+ type: :runtime
25
25
  requirement: &id001 !ruby/object:Gem::Requirement
26
26
  none: false
27
27
  requirements:
28
28
  - - ">="
29
29
  - !ruby/object:Gem::Version
30
- hash: 29
30
+ hash: 15
31
31
  segments:
32
32
  - 1
33
- - 3
34
- - 3
35
- version: 1.3.3
36
- type: :runtime
33
+ - 4
34
+ - 4
35
+ version: 1.4.4
36
+ name: nokogiri
37
37
  version_requirements: *id001
38
38
  - !ruby/object:Gem::Dependency
39
- name: rubyforge
40
39
  prerelease: false
40
+ type: :development
41
41
  requirement: &id002 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
44
  - - ">="
45
45
  - !ruby/object:Gem::Version
46
- hash: 7
46
+ hash: 27
47
47
  segments:
48
- - 2
49
48
  - 0
50
- - 4
51
- version: 2.0.4
52
- type: :development
49
+ - 8
50
+ version: "0.8"
51
+ name: rake
53
52
  version_requirements: *id002
54
53
  - !ruby/object:Gem::Dependency
55
- name: mocha
56
54
  prerelease: false
55
+ type: :development
57
56
  requirement: &id003 !ruby/object:Gem::Requirement
58
57
  none: false
59
58
  requirements:
60
- - - ">="
59
+ - - ~>
61
60
  - !ruby/object:Gem::Version
62
- hash: 25
61
+ hash: 7
63
62
  segments:
64
- - 0
65
- - 9
66
- version: "0.9"
67
- type: :development
63
+ - 2
64
+ - 2
65
+ version: "2.2"
66
+ name: minitest
68
67
  version_requirements: *id003
69
68
  - !ruby/object:Gem::Dependency
70
- name: shoulda
71
69
  prerelease: false
70
+ type: :development
72
71
  requirement: &id004 !ruby/object:Gem::Requirement
73
72
  none: false
74
73
  requirements:
75
- - - ">="
74
+ - - ~>
76
75
  - !ruby/object:Gem::Version
77
- hash: 23
76
+ hash: 15
78
77
  segments:
79
- - 2
80
- - 10
81
- version: "2.10"
82
- type: :development
78
+ - 1
79
+ - 0
80
+ version: "1.0"
81
+ name: rr
83
82
  version_requirements: *id004
84
83
  - !ruby/object:Gem::Dependency
85
- name: rake
86
84
  prerelease: false
85
+ type: :development
87
86
  requirement: &id005 !ruby/object:Gem::Requirement
88
87
  none: false
89
88
  requirements:
90
89
  - - ">="
91
90
  - !ruby/object:Gem::Version
92
- hash: 27
91
+ hash: 3
93
92
  segments:
94
93
  - 0
95
- - 8
96
- version: "0.8"
97
- type: :development
94
+ version: "0"
95
+ name: json
98
96
  version_requirements: *id005
99
97
  - !ruby/object:Gem::Dependency
100
- name: hoe
101
98
  prerelease: false
99
+ type: :development
102
100
  requirement: &id006 !ruby/object:Gem::Requirement
103
101
  none: false
104
102
  requirements:
105
103
  - - ">="
106
104
  - !ruby/object:Gem::Version
107
- hash: 21
105
+ hash: 3
108
106
  segments:
109
- - 2
110
- - 6
111
- - 1
112
- version: 2.6.1
113
- type: :development
107
+ - 0
108
+ version: "0"
109
+ name: hoe-gemspec
114
110
  version_requirements: *id006
111
+ - !ruby/object:Gem::Dependency
112
+ prerelease: false
113
+ type: :development
114
+ requirement: &id007 !ruby/object:Gem::Requirement
115
+ none: false
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ hash: 3
120
+ segments:
121
+ - 0
122
+ version: "0"
123
+ name: hoe-debugging
124
+ version_requirements: *id007
125
+ - !ruby/object:Gem::Dependency
126
+ prerelease: false
127
+ type: :development
128
+ requirement: &id008 !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ hash: 3
134
+ segments:
135
+ - 0
136
+ version: "0"
137
+ name: hoe-bundler
138
+ version_requirements: *id008
139
+ - !ruby/object:Gem::Dependency
140
+ prerelease: false
141
+ type: :development
142
+ requirement: &id009 !ruby/object:Gem::Requirement
143
+ none: false
144
+ requirements:
145
+ - - ">="
146
+ - !ruby/object:Gem::Version
147
+ hash: 3
148
+ segments:
149
+ - 0
150
+ version: "0"
151
+ name: hoe-git
152
+ version_requirements: *id009
153
+ - !ruby/object:Gem::Dependency
154
+ prerelease: false
155
+ type: :development
156
+ requirement: &id010 !ruby/object:Gem::Requirement
157
+ none: false
158
+ requirements:
159
+ - - ~>
160
+ - !ruby/object:Gem::Version
161
+ hash: 23
162
+ segments:
163
+ - 2
164
+ - 10
165
+ version: "2.10"
166
+ name: hoe
167
+ version_requirements: *id010
115
168
  description: |-
116
169
  Loofah is a general library for manipulating and transforming HTML/XML
117
170
  documents and fragments. It's built on top of Nokogiri and libxml2, so
@@ -161,6 +214,7 @@ files:
161
214
  - lib/loofah/scrubbers.rb
162
215
  - lib/loofah/xml/document.rb
163
216
  - lib/loofah/xml/document_fragment.rb
217
+ - test/assets/testdata_sanitizer_tests1.dat
164
218
  - test/helper.rb
165
219
  - test/html5/test_sanitizer.rb
166
220
  - test/integration/test_ad_hoc.rb
@@ -169,9 +223,11 @@ files:
169
223
  - test/integration/test_scrubbers.rb
170
224
  - test/integration/test_xml.rb
171
225
  - test/unit/test_api.rb
226
+ - test/unit/test_encoding.rb
172
227
  - test/unit/test_helpers.rb
173
228
  - test/unit/test_scrubber.rb
174
229
  - test/unit/test_scrubbers.rb
230
+ - .gemtest
175
231
  has_rdoc: true
176
232
  homepage: http://github.com/flavorjones/loofah
177
233
  licenses: []
@@ -203,18 +259,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
203
259
  requirements: []
204
260
 
205
261
  rubyforge_project: loofah
206
- rubygems_version: 1.3.7
262
+ rubygems_version: 1.6.0
207
263
  signing_key:
208
264
  specification_version: 3
209
265
  summary: Loofah is a general library for manipulating and transforming HTML/XML documents and fragments
210
266
  test_files:
211
- - test/integration/test_html.rb
212
- - test/integration/test_ad_hoc.rb
213
- - test/integration/test_helpers.rb
214
- - test/integration/test_scrubbers.rb
215
- - test/integration/test_xml.rb
216
- - test/html5/test_sanitizer.rb
217
267
  - test/unit/test_scrubber.rb
218
268
  - test/unit/test_helpers.rb
219
- - test/unit/test_scrubbers.rb
220
269
  - test/unit/test_api.rb
270
+ - test/unit/test_scrubbers.rb
271
+ - test/unit/test_encoding.rb
272
+ - test/html5/test_sanitizer.rb
273
+ - test/integration/test_helpers.rb
274
+ - test/integration/test_scrubbers.rb
275
+ - test/integration/test_ad_hoc.rb
276
+ - test/integration/test_xml.rb
277
+ - test/integration/test_html.rb