diff --git a/Gemfile b/Gemfile index 4a77753..f2a5244 100644 --- a/Gemfile +++ b/Gemfile @@ -7,4 +7,8 @@ else gem "rake", "~> 13.0" end +if Gem::Requirement.new(">= 3.3").satisfied_by?(Gem::Version.new(RUBY_VERSION)) + gem "base64" +end + gem "test-unit", "~> 3.5" diff --git a/lib/plist.rb b/lib/plist.rb index 2304992..0939cb3 100644 --- a/lib/plist.rb +++ b/lib/plist.rb @@ -9,7 +9,6 @@ # Distributed under the MIT License # -require 'base64' require 'cgi' require 'stringio' diff --git a/lib/plist/generator.rb b/lib/plist/generator.rb index 0b8af54..5d17d55 100644 --- a/lib/plist/generator.rb +++ b/lib/plist/generator.rb @@ -124,11 +124,9 @@ def tag(type, contents, level, &block) def data_tag(data, level) # note that apple plists are wrapped at a different length then - # what ruby's base64 wraps by default. - # I used #encode64 instead of #b64encode (which allows a length arg) - # because b64encode is b0rked and ignores the length arg. + # what ruby's pack wraps by default. tag('data', nil, level) do - Base64.encode64(data) + [data].pack("m") # equivalent to Base64.encode64(data) .gsub(/\s+/, '') .scan(/.{1,68}/o) .collect { |line| indent(line, level) } diff --git a/lib/plist/parser.rb b/lib/plist/parser.rb index 6b83ed4..038b194 100755 --- a/lib/plist/parser.rb +++ b/lib/plist/parser.rb @@ -246,10 +246,10 @@ def to_ruby end end - require 'base64' class PData < PTag def to_ruby - data = Base64.decode64(text.gsub(/\s+/, '')) unless text.nil? + # unpack("m")[0] is equivalent to Base64.decode64 + data = text.gsub(/\s+/, '').unpack("m")[0] unless text.nil? begin return Marshal.load(data) if options[:marshal] rescue Exception diff --git a/test/test_parser.rb b/test/test_parser.rb index 2ff4db5..ada9b2a 100755 --- a/test/test_parser.rb +++ b/test/test_parser.rb @@ -1,4 +1,5 @@ require 'test/unit' +require 'base64' require 'plist' class TestParser < Test::Unit::TestCase