snatch 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/lib/snatch/clean/html.rb +8 -6
- data/snatch.gemspec +1 -1
- data/spec/snatch/clean/html_spec.rb +2 -2
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.2
|
data/lib/snatch/clean/html.rb
CHANGED
@@ -12,8 +12,8 @@ class Snatch
|
|
12
12
|
|
13
13
|
def encode_mailtos(a)
|
14
14
|
if a['href'] =~ /^mailto:(.*)/
|
15
|
-
a['href'] = 'mailto:' + url_encode($1)
|
16
|
-
a.inner_html = html_encode(a.inner_html)
|
15
|
+
a['href'] = 'mailto:' + HTML.url_encode($1)
|
16
|
+
a.inner_html = HTML.html_encode(a.inner_html)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -48,11 +48,11 @@ class Snatch
|
|
48
48
|
new(doc, working_directory).update
|
49
49
|
end
|
50
50
|
|
51
|
-
def html_encode(string)
|
51
|
+
def self.html_encode(string)
|
52
52
|
string.gsub(/./){ |char| "&#x#{char.unpack('U')[0].to_s(16)};" }
|
53
53
|
end
|
54
54
|
|
55
|
-
def url_encode(string)
|
55
|
+
def self.url_encode(string)
|
56
56
|
string.gsub(/./) { |char| '%' + char.unpack('H2' * char.size).join('%').upcase }
|
57
57
|
end
|
58
58
|
|
@@ -62,11 +62,13 @@ class Snatch
|
|
62
62
|
@doc.search('//comment()').remove
|
63
63
|
|
64
64
|
HrefFixMethods.instance_methods.each do |m|
|
65
|
-
|
65
|
+
klass = Class.new { include HrefFixMethods }.new
|
66
|
+
@doc.css('a[href]').each { |a| klass.send m, a }
|
66
67
|
end
|
67
68
|
|
68
69
|
SrcFixMethods.instance_methods.each do |m|
|
69
|
-
|
70
|
+
klass = Class.new { include SrcFixMethods }.new
|
71
|
+
@doc.css('[src]').each { |a| klass.send m, a }
|
70
72
|
end
|
71
73
|
end
|
72
74
|
end
|
data/snatch.gemspec
CHANGED
@@ -48,8 +48,8 @@ describe Snatch::Clean::HTML do
|
|
48
48
|
|
49
49
|
it 'should encode email addresses' do
|
50
50
|
anchor = %Q{<a href="mailto:blah@exåmplé.cøm">blah@exåmplé.cøm</a>}
|
51
|
-
|
52
|
-
|
51
|
+
@html.class.should_receive(:url_encode).and_return('url_encode')
|
52
|
+
@html.class.should_receive(:html_encode).and_return('html_encode')
|
53
53
|
fix_node(:encode_mailtos, anchor) do |node|
|
54
54
|
node.should have_href('mailto:url_encode')
|
55
55
|
node.text.should == 'html_encode'
|