Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

Respect encodings when reading gemspecs #6599

Merged

Conversation

deivid-rodriguez
Copy link
Member

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.

gem.author = "Ivo Anjo"
gem.summary = "Unscratchable stuff"
end
G
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at how nice the version.rb file in this diff looks, we might want to change the G tag to RUBY everywhere :)

Copy link
Contributor

@eregon eregon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me!

lib/bundler.rb Outdated
@@ -444,7 +444,7 @@ def load_gemspec(file, validate = false)

def load_gemspec_uncached(file, validate = false)
path = Pathname.new(file)
contents = read_file(file)
contents = path.read(encoding: Encoding::UTF_8)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From the CI:

lib/bundler.rb:447:28: C: Style/HashSyntax: Use hash rockets syntax.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, should be fixed now!

lib/bundler.rb Outdated
@@ -444,7 +444,7 @@ def load_gemspec(file, validate = false)

def load_gemspec_uncached(file, validate = false)
path = Pathname.new(file)
contents = read_file(file)
contents = path.read(:encoding => Encoding::UTF_8)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's surprising Bundler still supports the very old Ruby 1.8.7.
Maybe File.open(file, "r:UTF-8", &:read) would work on 1.8.7 too.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Totally, I was bitten by the same thing in the PR that caused this regression as well.

Master (bundle 2) does not really support 1.8.7 anymore (the minimum required ruby version has been bumped to ruby 2.3). However, specs are still run against 1.8.7 in order to "ease backports". In my opinion this is wrong because easing backports comes at the cost of difficulting regular contributions (like this one). But it's no big deal I guess.

Just tried your suggestion, let's see if it works...

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the info, I agree in general. I filed #6600 just before seeing this, let's see.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It didn't work... 😞 Up to the maintainers how to follow up from here.

@eregon
Copy link
Contributor

eregon commented Jun 24, 2018

Maybe it's OK to skip this spec on 1.8.7?
IIRC, Ruby 1.8.7 has very limited support for Unicode characters, notably I think it doesn't quite like them in constants.
The rest seems to work fine, only this spec fails.

@deivid-rodriguez
Copy link
Member Author

Fine with me! Let me skip it.

@@ -63,6 +63,33 @@
expect(out).to include("Bundle complete!")
end

it "reads gemspecs respecting their encoding" do
skip "Too cool for 1.8" if RUBY_VERSION < "1.9"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not informative, please use a comment that explains why we need to skip 1.8 in this test.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about "unicode was probably not fully supported on 1.8"?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically the reason is that we have decided it's not worth even trying to make this work on 1.8. We're not sure it's actually supported and blind guessing from Travis logs feedback is... tough.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pushed a new skip message, hopefully more serious and informative :)

Copy link
Member

@colby-swandale colby-swandale left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to skip testing this spec on ruby 1.8.6

@colby-swandale
Copy link
Member

@bundlerbot r+

@bundlerbot
Copy link
Collaborator

📌 Commit 6df5585 has been approved by colby-swandale

@colby-swandale colby-swandale added this to the 1.16.3 milestone Jun 26, 2018
@bundlerbot
Copy link
Collaborator

⌛ Testing commit 6df5585 with merge cb18acc...

bundlerbot added a commit that referenced this pull request Jun 26, 2018
…n, 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.
@bundlerbot
Copy link
Collaborator

☀️ Test successful - status-travis
Approved by: colby-swandale
Pushing cb18acc to master...

@bundlerbot bundlerbot merged commit 6df5585 into rubygems:master Jun 26, 2018
@deivid-rodriguez deivid-rodriguez deleted the fix/gemspec_encoding_regression branch June 27, 2018 11:11
colby-swandale pushed a commit that referenced this pull request Jul 10, 2018
…n, 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 cb18acc)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants