snatch 1.0.10 → 1.0.11
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 +3 -2
- data/snatch.gemspec +1 -1
- data/spec/snatch/clean/html_spec.rb +7 -2
- metadata +1 -1
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.11
|
data/lib/snatch/clean/html.rb
CHANGED
@@ -24,8 +24,9 @@ class Snatch
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def prepend_slash(a)
|
27
|
-
includes_special_chars =
|
28
|
-
|
27
|
+
includes_special_chars = (%w(: .) & a['href'].split(//)).empty?
|
28
|
+
relative_upload = a['href'].match(/^#{UPLOADS_DIR}/)
|
29
|
+
a['href'] = a['href'].sub(%r{^/?}, '/') if includes_special_chars || relative_upload
|
29
30
|
end
|
30
31
|
|
31
32
|
def append_slash(a)
|
data/snatch.gemspec
CHANGED
@@ -106,18 +106,23 @@ describe Snatch::Clean::HTML do
|
|
106
106
|
end
|
107
107
|
|
108
108
|
describe "leading slashes and colons" do
|
109
|
-
it 'should
|
109
|
+
it 'should prepend a slash when there is no colon' do
|
110
110
|
fix_node(:prepend_slash, %Q{<a href="blah/file"></a>}) do |node|
|
111
111
|
node.should have_href('/blah/file')
|
112
112
|
end
|
113
113
|
end
|
114
114
|
|
115
|
-
it 'should not
|
115
|
+
it 'should not prepend a slash when there is a colon' do
|
116
116
|
fix_node(:prepend_slash, %Q{<a href="blah/file:wtf.txt"></a>}) do |node|
|
117
117
|
node.should have_href('blah/file:wtf.txt')
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
121
|
+
it 'should always prepend a slash on an upload' do
|
122
|
+
node = fix_node(:prepend_slash, '<a href="uploads/document.pdf"></a>')
|
123
|
+
node.should have_href('/uploads/document.pdf')
|
124
|
+
end
|
125
|
+
|
121
126
|
it 'should not add two slashes' do
|
122
127
|
fix_node(:prepend_slash, %Q{<a href="/blah/file.txt"></a>}) do |node|
|
123
128
|
node.should have_href('/blah/file.txt')
|