-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
Make the backquote operator always return a string #31253
Conversation
Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @schneems (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review. Please see the contribution instructions for more information. |
Are we unifying a behaviour that's since been unified upstream in the other direction?
Everywhere I tried this just now I got an ENOENT, not a string. 😕 |
Oops, that description I added the last minute was wrong, I’ll fix it shortly. |
It sounds like maybe we should just remove the method. I don't think it was a strong opinion that it should fail quietly -- we just wanted it to do something consistently. If upstream is now meeting that condition, we don't need to do anything. |
@matthewd Sorry, I've fixed the description.
That'd be an idea, but at least the upstream (Ruby) did not change anything with the said behavior. |
It clearly did, because the comment on this method says that [when it was written] on Unix,
(Interestingly, an empty string, not a nil. I don't have 1.8.6 nearby to compare; maybe that was always inaccurate.) I think this reinforces the idea that we should be removing it: we standardized on the 1.8.7 Unix behaviour, and now we're just (very) out of date. |
Hmm. Is it really safe to break the assumption among Rails users that a backquote operator wouldn’t raise ENOENT? I have no particular opinion and just think it is unexpectable and inappropriate for it to return nil. |
Anything stopping this from being merged? |
I agree with Matthew that we should remove this method. @knu can you remove the method and add a CHANGELOG entry? |
1459340
to
37725fc
Compare
@rafaelfranca Done. Should I squash the commits? |
require "active_support/core_ext/kernel" | ||
|
||
class KernelTest < ActiveSupport::TestCase | ||
include ActiveSupport::Testing::Stream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This has no longer used.
Friendly ping. |
@knu sorry for the delay -- yes, please go ahead and squash. 👍 @rafaelfranca do you have any thoughts on whether we should deprecate this first? I'm leaning towards treating it as a bugfix (though one we wouldn't backport) and merging this as is, but we could put a deprecation inside the |
bc5807e
to
4267c64
Compare
@matthewd I've squashed all commits into one and updated the commit message. I agree you can treat this as a mere bug fix! |
I's also treat this as a bug fix. No need for deprecation. |
4267c64
to
30c00d3
Compare
Someone? |
I want to this include in Rails 6.0. |
ActiveSupport overrides `` Kernel#` `` so that it would not raise `Errno::ENOENT` but return `nil` instead (due to the last statement `STDERR.puts` returning nil) if a given command were not found. Because of this, you cannot safely say somthing like `` `command`.chomp `` when ActiveSupport is loaded. It turns out that this is an outdated monkey patch for Windows platforms to emulate Unix behavior on an ancient version of Ruby, and it should be removed by now.
9f1295c
to
545b6e5
Compare
@y-yagi Done, and the CI build passed. |
@knu Thanks! |
This fixes this behavior:
With this PR merged:
Summary
ActiveSupport overrides
Kernel#`
so that it would not raiseErrno::ENOENT
but returnnil
instead if a given command were notfound. In vanilla Ruby you can safely say
`command`.strip
or`command`.empty?
but with ActiveSupport loaded that's not thecase anymore.
A good function wrapper does not change the return value type, so the
core extension of
Kernel#`
should return an empty (mutable)string when it decides to suppress an exception.