carrierwave-base64 2.5.3 → 2.6.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7dff45d674c5e293cfead7291d9a6c53be492672
4
- data.tar.gz: 628856bf8cccdf7dd686ae2ee57deef2d5077e4d
3
+ metadata.gz: fb281b2683a576956173494d155b372c985499a8
4
+ data.tar.gz: e28479d1490ba1a00ce8e20a862f9636fa1f78f5
5
5
  SHA512:
6
- metadata.gz: dee1bc71961ec31d297fb70af591fe833c4934bb38685e862ab33ff58bc9f69e34f4850b26a86b7189c8c0c775e581e89d20e0f89b5ea56c20e05e1957dc3169
7
- data.tar.gz: d4be112dc0dec5e83a78e6bd1027422f559da7f8d61f3afc1bb30baee75ece8783823dd2026bf5e78d062f01b978c2b16ef78de5af9273a1f8ef44f98ddc64e2
6
+ metadata.gz: f102337cef6625d4ec0ea0e281c1d4e0ff57af69d9778d0b8073e4379f1fcea9ef2212002683f92643b83b7ddd03a3bf1e8c18aec92908485a709e6beb1b1098
7
+ data.tar.gz: 7e18c8cc657eebcb475caf0b6e0c5a541ada043ebb09b5506354b49b0ae427ba5f0ba1c4055c2970ecc1080148852d77c6cc65a13df11759fe9199b33e899279
@@ -1,5 +1,10 @@
1
1
  # carrierwave-base64 changelog
2
2
 
3
+ ## 2.6.0
4
+
5
+ - Fixed the issue with base64 string not being validated (#64, @sjdrabbani)
6
+ - Sending a base64 string with missing or unknown MIME Type will raise `Carrierwave::Base64::UnknownMimeTypeError` (@lebedev-yury)
7
+
3
8
  ## 2.5.3
4
9
 
5
10
  - Fixed an incorrect deprecation warning that fired even with `file_name` option set to a Proc (#60, @frodsan)
@@ -1,5 +1,3 @@
1
- # coding: utf-8
2
-
3
1
  lib = File.expand_path('../lib', __FILE__)
4
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
3
 
@@ -1,5 +1,6 @@
1
1
  require 'mime/types/full'
2
2
  require 'carrierwave/base64/version'
3
+ require 'carrierwave/base64/exceptions'
3
4
  require 'carrierwave/base64/base64_string_io'
4
5
  require 'carrierwave/base64/adapter'
5
6
 
@@ -1,19 +1,14 @@
1
1
  module Carrierwave
2
2
  module Base64
3
3
  class Base64StringIO < StringIO
4
- class ArgumentError < StandardError; end
5
-
6
4
  attr_accessor :file_extension, :file_name
7
5
 
8
6
  def initialize(encoded_file, file_name)
9
7
  description, encoded_bytes = encoded_file.split(',')
10
8
 
11
- raise ArgumentError unless encoded_bytes
12
- raise ArgumentError if encoded_bytes.eql?('(null)')
13
-
14
9
  @file_name = file_name
15
10
  @file_extension = get_file_extension description
16
- bytes = ::Base64.decode64 encoded_bytes
11
+ bytes = ::Base64.strict_decode64 encoded_bytes
17
12
 
18
13
  super bytes
19
14
  end
@@ -28,7 +23,8 @@ module Carrierwave
28
23
  content_type = description.split(';base64').first
29
24
  mime_type = MIME::Types[content_type].first
30
25
  unless mime_type
31
- raise ArgumentError, "Unknown MIME type: #{content_type}"
26
+ raise Carrierwave::Base64::UnknownMimeTypeError,
27
+ "Unknown MIME type: #{content_type}"
32
28
  end
33
29
  mime_type.preferred_extension
34
30
  end
@@ -0,0 +1,5 @@
1
+ module Carrierwave
2
+ module Base64
3
+ class UnknownMimeTypeError < ::ArgumentError; end
4
+ end
5
+ end
@@ -1,5 +1,5 @@
1
1
  module Carrierwave
2
2
  module Base64
3
- VERSION = '2.5.3'.freeze
3
+ VERSION = '2.6.0'.freeze
4
4
  end
5
5
  end
@@ -3,7 +3,7 @@ RSpec.describe Carrierwave::Base64::Base64StringIO do
3
3
  image/jpeg application/pdf audio/mpeg].each do |content_type|
4
4
  context "correct #{content_type} data" do
5
5
  let(:data) do
6
- "data:#{content_type};base64,/9j/4AAQSkZJRgABAQEASABKdhH//2Q=="
6
+ "data:#{content_type};base64,VGhpcyBpcyB0ZXN0IHN0cmluZw=="
7
7
  end
8
8
 
9
9
  let(:file_extension) do
@@ -36,16 +36,22 @@ RSpec.describe Carrierwave::Base64::Base64StringIO do
36
36
  end
37
37
 
38
38
  context 'invalid image data' do
39
- it 'raises an ArgumentError if Data URI content type is missing' do
39
+ it 'raises UnknownMimeTypeError for unknown mime types' do
40
40
  expect do
41
41
  described_class.new('/9j/4AAQSkZJRgABAQEASABIAADKdhH//2Q==', 'file')
42
- end.to raise_error(Carrierwave::Base64::Base64StringIO::ArgumentError)
42
+ end.to raise_error(Carrierwave::Base64::UnknownMimeTypeError)
43
43
  end
44
44
 
45
- it 'raises ArgumentError if base64 data eql (null)' do
45
+ it 'raises ArgumentError if base64 data equals to (null)' do
46
46
  expect do
47
47
  described_class.new('data:image/jpeg;base64,(null)', 'file')
48
- end.to raise_error(Carrierwave::Base64::Base64StringIO::ArgumentError)
48
+ end.to raise_error(ArgumentError, 'invalid base64')
49
+ end
50
+
51
+ it 'raises ArgumentError if base64 data contains white space' do
52
+ expect do
53
+ described_class.new 'data:image/jpeg;base64,VGhpcyBpc yB0Z==', 'file'
54
+ end.to raise_error(ArgumentError, 'invalid base64')
49
55
  end
50
56
  end
51
57
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: carrierwave-base64
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.5.3
4
+ version: 2.6.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yury Lebedev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-30 00:00:00.000000000 Z
11
+ date: 2017-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: carrierwave
@@ -199,6 +199,7 @@ files:
199
199
  - lib/carrierwave/base64.rb
200
200
  - lib/carrierwave/base64/adapter.rb
201
201
  - lib/carrierwave/base64/base64_string_io.rb
202
+ - lib/carrierwave/base64/exceptions.rb
202
203
  - lib/carrierwave/base64/version.rb
203
204
  - spec/adapter_spec.rb
204
205
  - spec/base64_string_io_spec.rb
@@ -228,7 +229,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
228
229
  version: '0'
229
230
  requirements: []
230
231
  rubyforge_project:
231
- rubygems_version: 2.6.8
232
+ rubygems_version: 2.6.11
232
233
  signing_key:
233
234
  specification_version: 4
234
235
  summary: Upload images encoded as base64 to carrierwave.