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

Ruby 2.7 compatibility #28

Merged
merged 7 commits into from
Jan 9, 2020
Merged

Ruby 2.7 compatibility #28

merged 7 commits into from
Jan 9, 2020

Conversation

janko
Copy link
Member

@janko janko commented Dec 27, 2019

In Ruby 2.7 Nil#to_s now returns a frozen string, which caused FrozenError exceptions in CompositeIO#read when outbuf was nil. So, we update the code to handle this properly.

Ruby 2.7 also added deprecation warnings for the upcoming separation of positional and keyword arguments that is planned for Ruby 3.0. There were couple of specs that triggered the warning, so I updated the code to use the correct syntax.

I updated the Travis CI matrix to add 2.5, 2.6, and 2.7.

.travis.yml Outdated
@@ -19,13 +19,16 @@ rvm:
# Include JRuby first because it takes the longest
- jruby-9.1.13.0
- 2.2
- 2.3.4
- 2.4.1
- 2.3
Copy link
Member

Choose a reason for hiding this comment

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

We don't need to support those anymore.

Copy link
Member

@ixti ixti left a comment

Choose a reason for hiding this comment

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

Thank you!

outbuf = outbuf.to_s.clear
# buffer in JRuby is sometimes US-ASCII, force to ASCII-8BIT
outbuf.force_encoding(Encoding::BINARY)
data = outbuf ? outbuf.clear.force_encoding(Encoding::BINARY) : "".b
Copy link
Member

Choose a reason for hiding this comment

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

I feel neutral, but probably safenave here will look better:

Suggested change
data = outbuf ? outbuf.clear.force_encoding(Encoding::BINARY) : "".b
data = outbuf&.clear&.force_encoding(Encoding::BINARY) || "".b

Copy link
Member

Choose a reason for hiding this comment

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

Or two lines 😂:

Suggested change
data = outbuf ? outbuf.clear.force_encoding(Encoding::BINARY) : "".b
outbuf &&= outbuf.clear.force_encoding(Encoding::BINARY)
outbuf ||= "".b

Copy link
Member

Choose a reason for hiding this comment

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

Just to make it clear - I'm fine to keep the code the way it is now in the PR. Just throwing in ideas how to avoid ternary operator (I usually don't like it unless it's something super simple - like when branches are simple variables or literals).

Copy link
Member Author

@janko janko Dec 27, 2019

Choose a reason for hiding this comment

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

Makes sense about avoiding the ternary operator. I want the data variable in order to make a distinction between outbuf being set and not, so how about this?

data   = outbuf.clear.force_encoding(Encoding::BINARY) if outbuf
data ||= "".b

Copy link
Member

Choose a reason for hiding this comment

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

Works for me 👍

.travis.yml Outdated Show resolved Hide resolved
.rubocop.yml Outdated
Comment on lines 16 to 18
Metrics/CyclomaticComplexity:
Max: 7

Copy link
Member

Choose a reason for hiding this comment

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

Let me think a bit on how to avoid changing this.

.rubocop.yml Outdated
Comment on lines 68 to 70

Style/Next:
Enabled: false
Copy link
Member

Choose a reason for hiding this comment

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

Same about this one.

@janko
Copy link
Member Author

janko commented Jan 4, 2020

@ixti I was able to fix both .rubocop.yml offenses 👍

@janko
Copy link
Member Author

janko commented Jan 9, 2020

@ixti Any chance we could get this merged and released? Normally if it were only kwargs warnings it wouldn't be a big deal, but these are actual errors, so it would be useful to get the fix released 😃

Afterwards, we can bump http-form_data version on the http gem and get it released as well.

This would help a lot in getting Shrine updated for Ruby 2.7 🙏

janko added 6 commits January 9, 2020 13:02
I believe this option was changed in RubyGems 3.0.
These have reached EOL.
I don't think we need to specify Bundler at all in the gemspec, so we
remove it.
As of Ruby 2.7, Nil#to_s returns a frozen string. We update the code to
ensure a mutable string is returned for the output buffer.
@janko janko force-pushed the ruby-2-7-compatibility branch from b3df1d6 to 1095586 Compare January 9, 2020 12:09
@janko
Copy link
Member Author

janko commented Jan 9, 2020

I also cleaned up the commit history 😅

Copy link
Member

@ixti ixti left a comment

Choose a reason for hiding this comment

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

Please make supported list of rubies explicit, and then it will be fine. ))

README.md Outdated
* Ruby 2.3.x
* Ruby 2.4.x
* JRuby 9.1.x.x
* Ruby 2.4+
Copy link
Member

Choose a reason for hiding this comment

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

After recent incident in http gem I would like to keep this list explicit

Copy link
Member Author

Choose a reason for hiding this comment

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

Updated 👍

Copy link
Member

@ixti ixti left a comment

Choose a reason for hiding this comment

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

Looks awesome. Thank you very much.

@ixti ixti merged commit 54c8ba2 into httprb:master Jan 9, 2020
@ixti
Copy link
Member

ixti commented Jan 9, 2020

I'll cut release shortly.

@janko janko deleted the ruby-2-7-compatibility branch January 9, 2020 14:08
@ixti
Copy link
Member

ixti commented Jan 9, 2020

Released as v2.2.0

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Mar 21, 2020
Update ruby-http-form_data to 2.3.0.

pkgsrc change: add "USE_LANGAUGES=	# none".


## 2.3.0 (2020-03-08)

* [#29](httprb/form_data#29)
  Enhance HTTP::FormData::Urlencoded with per-instance encoder.
  [@summera][]


## 2.2.0 (2020-01-09)

* [#28](httprb/form_data#28)
  Ruby 2.7 compatibility.
  [@janko][]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants