snatch 1.0.10 → 1.0.11

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.10
1
+ 1.0.11
@@ -24,8 +24,9 @@ class Snatch
24
24
  end
25
25
 
26
26
  def prepend_slash(a)
27
- includes_special_chars = !(%w(: .) & a['href'].split(//)).empty?
28
- a['href'] = a['href'].sub(%r{^/?}, '/') unless includes_special_chars
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
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{snatch}
8
- s.version = "1.0.10"
8
+ s.version = "1.0.11"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["James Conroy-Finn"]
@@ -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 append a slash when there is no colon' do
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 append a slash when there is a colon' do
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')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snatch
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.10
4
+ version: 1.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Conroy-Finn