Make the backquote operator always return a string #31253
This fixes this behavior:
# Vanilla Ruby (on unix) `nonexistentcommand` #=> Errno::ENOENT `nonexistentcommand >/dev/null` == "" # With ActiveSupport loaded `nonexistentcommand` == nil # I believe this should be fixed `nonexistentcommand >/dev/null` == "" # With an error message on stderr
With this PR merged:
# With ActiveSupport loaded `nonexistentcommand` == "" # With an error message on stderr `nonexistentcommand >/dev/null` == "" # With an error message from the shell on stderr
A good function wrapper does not change the return value type, so the
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.
@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.
@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
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.