Compare commits

...

3 Commits

Author SHA1 Message Date
Jordan Sissel ac0ecdd101 Move `require` closer to where it is used.
This helps avoid a startup crash on Ruby 1.9.3 where the `rexml` gem
crashes when loaded due to syntax errors.

Fixes #1798, #1800, #1784
2022-11-02 21:47:47 -07:00
Jordan Sissel afc7c6f434 Call String#dup on RUBY_VERSION to avoid crashing on older ruby versions
On older versions of rubygems, `Gem::Version.new(...)` calls
`String#strip!` on the argument in the constructor. This causes a
problem on Ruby 1.9.3 where the RUBY_VERSION constant is a frozen
string.

The workaround is to make a copy of this string that is unfrozen, and
`String#dup` seems to work :)
2022-11-02 21:47:47 -07:00
Jordan Sissel 0a07c00639 Remove 'json' gem dependency.
The original `json` gem dependency was added in the original fpm.gemspec
because, at the time, Ruby 1.8.7 was common and required an external
`json` dependency for parsing JSON.

Later, Ruby releases since 1.9.1 have bundled `json`[1].

Therefore, it feels safe to remove this dependency. As a bonus, the
rubygems `json` gem places requirements on the minimum version of Ruby.
At this time, the latest `json` gem requires Ruby >= 2.3.

If the `json` gem dependency is removed, fpm will still retain the
ability to process JSON while lowering the minimum required Ruby version
to Ruby 1.9.x -- It's not perfect, but it's a start! :)

[1] https://docs.ruby-lang.org/en/2.3.0/NEWS-1_9_1.html

The idea for this change change came originally from a discussion
with @edolnx in #1949

Fixes #1741, #1264, #1949
2022-11-02 21:47:47 -07:00
3 changed files with 6 additions and 6 deletions

View File

@ -22,10 +22,6 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 1.9.3'
# For parsing JSON (required for some Python support, etc)
# http://flori.github.com/json/doc/index.html
spec.add_dependency("json", ">= 1.7.7", "< 3.0") # license: Ruby License
# For logging
# https://github.com/jordansissel/ruby-cabin
spec.add_dependency("cabin", ">= 0.6.0") # license: Apache 2

View File

@ -4,7 +4,6 @@ require "fileutils"
require "fpm/package/dir"
require 'tempfile' # stdlib
require 'pathname' # stdlib
require 'rexml/document' # stdlib
# Use an OS X pkg built with pkgbuild.
#
@ -103,6 +102,7 @@ class FPM::Package::OSXpkg < FPM::Package
# Extract name and version from PackageInfo XML
def extract_info(package)
require 'rexml/document'
build_path("expand").tap do |path|
doc = REXML::Document.new File.open(File.join(path, "PackageInfo"))
pkginfo_elem = doc.elements["pkg-info"]

View File

@ -421,7 +421,11 @@ module FPM::Util
# to invoke ERB.new correctly and without printed warnings.
# References: https://github.com/jordansissel/fpm/issues/1894
# Honestly, I'm not sure if Gem::Version is correct to use in this situation, but it works.
if Gem::Version.new(RUBY_VERSION) < Gem::Version.new("3.1.0")
# on older versions of Ruby, RUBY_VERSION is a frozen string, and
# Gem::Version.new calls String#strip! which throws an exception.
# so we have to call String#dup to get an unfrozen copy.
if Gem::Version.new(RUBY_VERSION.dup) < Gem::Version.new("3.1.0")
# Ruby 3.0.x and older
return ERB.new(template_code, nil, "-")
else