summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThe Bundler Bot <bot@bundler.io>2018-06-26 10:29:00 +0000
committerColby Swandale <hello@colby.fyi>2018-07-10 23:02:45 +1000
commit920f0e2e511c14ea62a07cba3a20ec541ad4d9b5 (patch)
treea1f29793b598367b0c229f3c1e79773518495eb3
parent912fbb8c7c1b876af78d404c57b790ffc87815bf (diff)
downloadbundler-920f0e2e511c14ea62a07cba3a20ec541ad4d9b5.tar.gz
Auto merge of #6599 - deivid-rodriguez:fix/gemspec_encoding_regression, r=colby-swandale
Respect encodings when reading gemspecs This PR fixes #6598. Thanks @eregon for the help and the explanation that helped me understand the issue :)! ### What was the end-user problem that led to this PR? On gems using UTF-8 symbols defined in other files in their gemspecs, `bundle install` would crash. ### What was your diagnosis of the problem? The problem was that since #6279 gemspecs are read binarily. However, files required from them as read as text. That means that the constants defined on those files and used in the gemspec are interpreted different and thus don't match. ### What is your fix for the problem, implemented in this PR? My fix is to go back to reading gemspec as text again. Explictly passing the encoding when reading them still fixes the problem that the PR introducing the regression was meant to fix. ### Why did you choose this fix out of the possible options? I chose this fix because it fixes the problem, and keeps the situation that the PR introducing the regression fixed also working. (cherry picked from commit cb18acc2983b6ef11d6710d8b5ef15134922ca60)
-rw-r--r--lib/bundler.rb2
-rw-r--r--spec/install/gemspecs_spec.rb27
2 files changed, 28 insertions, 1 deletions
diff --git a/lib/bundler.rb b/lib/bundler.rb
index beac9f1dff..82182d30eb 100644
--- a/lib/bundler.rb
+++ b/lib/bundler.rb
@@ -430,7 +430,7 @@ EOF
def load_gemspec_uncached(file, validate = false)
path = Pathname.new(file)
- contents = read_file(file)
+ contents = File.open(file, "r:UTF-8", &:read)
spec = if contents.start_with?("---") # YAML header
eval_yaml_gemspec(path, contents)
else
diff --git a/spec/install/gemspecs_spec.rb b/spec/install/gemspecs_spec.rb
index 5b6778bdd4..ef5e8e90e6 100644
--- a/spec/install/gemspecs_spec.rb
+++ b/spec/install/gemspecs_spec.rb
@@ -63,6 +63,33 @@ RSpec.describe "bundle install" do
expect(out).to include("Bundle complete!")
end
+ it "reads gemspecs respecting their encoding" do
+ skip "unicode constants are most likely not supported on 1.8" if RUBY_VERSION < "1.9"
+
+ create_file("version.rb", <<-RUBY)
+ module Persistent💎
+ VERSION = "0.0.1"
+ end
+ RUBY
+
+ create_file("persistent-dmnd.gemspec", <<-G)
+ require_relative "version"
+
+ Gem::Specification.new do |gem|
+ gem.name = "persistent-dmnd"
+ gem.version = Persistent💎::VERSION
+ gem.author = "Ivo Anjo"
+ gem.summary = "Unscratchable stuff"
+ end
+ G
+
+ install_gemfile <<-G
+ gemspec
+ G
+
+ expect(out).to include("Bundle complete!")
+ end
+
context "when ruby version is specified in gemspec and gemfile" do
it "installs when patch level is not specified and the version matches" do
build_lib("foo", :path => bundled_app) do |s|