hpricot-scrub 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.txt +9 -0
- data/Manifest.txt +11 -0
- data/README.txt +9 -0
- data/Rakefile +53 -0
- data/examples/config.yml +47 -0
- data/lib/hpricot_scrub.rb +2 -0
- data/lib/hpricot_scrub/version.rb +9 -0
- data/setup.rb +1585 -0
- data/test/hpricot_scrub_test.rb +45 -0
- data/test/scrubber_data.rb +14 -0
- data/test/test_helper.rb +8 -0
- metadata +64 -0
@@ -0,0 +1,45 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/test_helper.rb'
|
2
|
+
require File.dirname(__FILE__) + '/scrubber_data.rb'
|
3
|
+
|
4
|
+
class HpricotScrubTest < Test::Unit::TestCase
|
5
|
+
|
6
|
+
def setup
|
7
|
+
@clean = Hpricot(MARKUP).scrub.inner_html
|
8
|
+
@config = YAML.load_file('examples/config.yml')
|
9
|
+
end
|
10
|
+
|
11
|
+
def test_full_scrub
|
12
|
+
doc = Hpricot(MARKUP).scrub
|
13
|
+
# using the divisor search throws warnings in test
|
14
|
+
assert_tag_count(doc, 'a', 0)
|
15
|
+
assert_tag_count(doc, 'p', 0)
|
16
|
+
assert_tag_count(doc, 'img', 0)
|
17
|
+
assert_tag_count(doc, 'br', 0)
|
18
|
+
assert_tag_count(doc, 'div', 0)
|
19
|
+
assert_tag_count(doc, 'script', 0)
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_partial_scrub
|
23
|
+
full = Hpricot(MARKUP)
|
24
|
+
doc = Hpricot(MARKUP).scrub(@config)
|
25
|
+
# using the divisor search throws warnings in test
|
26
|
+
assert_tag_count(doc, 'a', 0)
|
27
|
+
assert_tag_count(doc, 'p', full.search('//p').size)
|
28
|
+
assert_tag_count(doc, 'div', full.search('//div').size)
|
29
|
+
assert_tag_count(doc, 'img', full.search('//img').size)
|
30
|
+
assert_tag_count(doc, 'br', full.search('//br').size)
|
31
|
+
assert_tag_count(doc, 'script', 0)
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_string_scrub
|
35
|
+
formatted = MARKUP
|
36
|
+
assert formatted.scrub == @clean
|
37
|
+
assert formatted == MARKUP
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_string_scrub!
|
41
|
+
formatted = MARKUP
|
42
|
+
assert formatted.scrub! == @clean
|
43
|
+
assert formatted == @clean
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
MARKUP = <<-EOS
|
2
|
+
<p>Some <b>bold junk</b> here...</p>
|
3
|
+
<p>Some more junk <i>here...</i><br></p>
|
4
|
+
<p>Still more junk <u>here</u>... </p>
|
5
|
+
<p><img title="nothing to see here" alt="nothing to see here" mce_src="http://example.com/imgtest.png" src="http://example.com/imgtest.png" align="middle" border="1" height="240" hspace="5" vspace="5" width="320"> </p>
|
6
|
+
<p> And a <a title="Just a link" target="_blank" mce_href="http://example.com/nothing.html" href="http://example.com/nothing.html">link</a> just because</p>
|
7
|
+
<p><div>some stuff in here</div><img title="nothing to see here" alt="nothing to see here" mce_src="http://example.com/imgtest.png" src="http://example.com/imgtest.png" align="middle" border="1" height="240" hspace="5" vspace="5" width="320"></p>
|
8
|
+
<a name="junk"></a>
|
9
|
+
<p><script type="text/javascript">//nasty bits go here
|
10
|
+
alert("gotcha");</script><img src="http://content.example.com/content/3587a2f6ee641074fec4e7534c01655326c218ec">how about an <a href="javascript:alert('gotcha')">inline script</a>
|
11
|
+
</p>
|
12
|
+
<span>some random unclosed span
|
13
|
+
<style type="text/css">.foo {color:blue}</style>
|
14
|
+
EOS
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.1
|
3
|
+
specification_version: 1
|
4
|
+
name: hpricot-scrub
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.2.0
|
7
|
+
date: 2007-03-04 00:00:00 -08:00
|
8
|
+
summary: Scrub HTML with Hpricot
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: michael@underpantsgnome.com
|
12
|
+
homepage: http://trac.underpantsgnome.com/hpricot_scrub/
|
13
|
+
rubyforge_project: hpricot-scrub
|
14
|
+
description: Scrub HTML with Hpricot
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- UnderpantsGnome
|
31
|
+
files:
|
32
|
+
- Rakefile
|
33
|
+
- README.txt
|
34
|
+
- CHANGELOG.txt
|
35
|
+
- Manifest.txt
|
36
|
+
- setup.rb
|
37
|
+
- lib/hpricot_scrub/version.rb
|
38
|
+
- lib/hpricot_scrub.rb
|
39
|
+
- test/test_helper.rb
|
40
|
+
- test/scrubber_data.rb
|
41
|
+
- test/hpricot_scrub_test.rb
|
42
|
+
- examples/config.yml
|
43
|
+
test_files:
|
44
|
+
- test/hpricot_scrub_test.rb
|
45
|
+
rdoc_options: []
|
46
|
+
|
47
|
+
extra_rdoc_files: []
|
48
|
+
|
49
|
+
executables: []
|
50
|
+
|
51
|
+
extensions: []
|
52
|
+
|
53
|
+
requirements: []
|
54
|
+
|
55
|
+
dependencies:
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: hpricot
|
58
|
+
version_requirement:
|
59
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0.5"
|
64
|
+
version:
|