has_image 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +5 -0
- data/lib/has_image/storage.rb +7 -1
- data/test/storage_test.rb +18 -0
- metadata +2 -2
data/CHANGELOG
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
2008-10-09 Dima Sabanin <sdmitry@gmail.com>
|
2
|
+
* Fixed display of images with special symbols in the name,
|
3
|
+
like '2777-nipple-+-apple-napple.jpg'. + is reserved by HTTP.
|
4
|
+
Now escaping filenames before giving them back in #public_path()
|
5
|
+
|
1
6
|
2008-09-10 Norman Clarke <norman@randomba.org>
|
2
7
|
* Fixed images not being converted to target format.
|
3
8
|
|
data/lib/has_image/storage.rb
CHANGED
@@ -87,7 +87,13 @@ module HasImage
|
|
87
87
|
#
|
88
88
|
# /photos/0000/0001/3er0zs.jpg
|
89
89
|
def public_path_for(object, thumbnail = nil)
|
90
|
-
filesystem_path_for(object, thumbnail).gsub(/\A.*public/, '')
|
90
|
+
webpath = filesystem_path_for(object, thumbnail).gsub(/\A.*public/, '')
|
91
|
+
escape_file_name_for_http(webpath)
|
92
|
+
end
|
93
|
+
|
94
|
+
def escape_file_name_for_http(webpath)
|
95
|
+
dir, file = File.split(webpath)
|
96
|
+
File.join(dir, CGI.escape(file))
|
91
97
|
end
|
92
98
|
|
93
99
|
# Deletes the images and directory that contains them.
|
data/test/storage_test.rb
CHANGED
@@ -40,6 +40,24 @@ class StorageTest < Test::Unit::TestCase
|
|
40
40
|
assert_equal "/tests/0000/0001/mypic_square.jpg", @storage.public_path_for(pic, :square)
|
41
41
|
end
|
42
42
|
|
43
|
+
def test_public_path_for_image_with_html_special_symbols_in_name
|
44
|
+
@storage = HasImage::Storage.new(default_options.merge(:base_path => '/public'))
|
45
|
+
pic = stub(:has_image_file => "my+pic", :has_image_id => 1)
|
46
|
+
assert_equal "/tests/0000/0001/my%2Bpic_square.jpg", @storage.public_path_for(pic, :square)
|
47
|
+
end
|
48
|
+
|
49
|
+
def test_escape_file_name_for_http
|
50
|
+
@storage = HasImage::Storage.new(default_options.merge(:base_path => '/public'))
|
51
|
+
real = @storage.escape_file_name_for_http("/tests/0000/0001/mypic+square?something.jpg")
|
52
|
+
assert_equal "/tests/0000/0001/mypic%2Bsquare%3Fsomething.jpg", real
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_escape_file_name_for_http_escapes_only_filename
|
56
|
+
@storage = HasImage::Storage.new(default_options.merge(:base_path => '/public'))
|
57
|
+
real = @storage.escape_file_name_for_http("/tests/00+00/0001/mypic+square?something.jpg")
|
58
|
+
assert_equal "/tests/00+00/0001/mypic%2Bsquare%3Fsomething.jpg", real
|
59
|
+
end
|
60
|
+
|
43
61
|
def test_filename_for
|
44
62
|
@storage = HasImage::Storage.new(default_options)
|
45
63
|
assert_equal "test.jpg", @storage.send(:file_name_for, "test")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: has_image
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Norman Clarke
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-09
|
12
|
+
date: 2008-10-09 00:00:00 -03:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|