Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove runtime dependency on base64 gem to fix Ruby 3.3 warning #63

Merged
merged 4 commits into from
Dec 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
1 change: 0 additions & 1 deletion lib/plist.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
# Distributed under the MIT License
#

require 'base64'
require 'cgi'
require 'stringio'

Expand Down
6 changes: 2 additions & 4 deletions lib/plist/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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) }
Expand Down
4 changes: 2 additions & 2 deletions lib/plist/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/test_parser.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
require 'test/unit'
require 'base64'
require 'plist'

class TestParser < Test::Unit::TestCase
Expand Down