-
Notifications
You must be signed in to change notification settings - Fork 613
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
Rake removes trailing whitespaces from parameters when task is being executed from command line. #216
Comments
+1 empty string arguments are interpreted to nil...but I was relying on them being a string. i.e. rake sometask[''] now evaluates that empty string to nil |
Nice catch @trushkevich I can reproduce the same you experience. After troubleshooting a bit, it seems like rake should actually remove leading whitespaces, it's what it currently does for every other argument except the first one.
|
Personally I would expect it not to trim anything at all. May be in some cases it somehow makes sense (but wouldn't it be better to just pass a raw value and let user decide what he wants to do?), like in your example, but e.g. in both following cases
it is pretty clear that the intention is to pass a whitespace as an argument (it could be for example specifying a separator character for some data output - just a quick idea from the top of my mind) - but currently it is impossible. And of course the behavior should be consistent with what we see in the console in any case. |
Maybe. Not sure. The thing is that current rake behavior is: trim everything except leading whitespaces for first argument only. So it's currently inconsistent. I'd rather, at least for now, achieve consistency by just fixing that trimming corner-case than by removing trimming of all leading and trailing spaces in all arguments. The later seems a lot more likely to break existing users rake tasks than the former.
I think it depends on the case.
|
I've been referring to those 2 examples I provided, and even provided a possible use-case of passing a whitespace to a rake task (separator), so I think there is no ambiguity and the intention in those 2 cases is pretty clear. Sorry, but to my mind your commit does not solve the issue I described. BTW @grzuy in fact you discovered an interesting point. See: single argument task :ws, [:str] => :environment do |t, args|
args.each {|a| puts a.inspect }
end command line: $ rake ws[' 1 , 2 , 3']
[:str, " 1"] console: 2.5.0 :002 > Rake::Task['ws'].invoke(' 1 , 2 , 3')
[:str, " 1 , 2 , 3"] multiple arguments task :ws, [:s1, :s2, :s3] => :environment do |t, args|
args.each {|a| puts a.inspect }
end command line: $ rake ws[' 1 , 2 , 3']
[:s1, " 1"]
[:s2, "2"]
[:s3, "3"] console: 2.5.0 :002 > Rake::Task['ws'].invoke(' 1 , 2 , 3')
[:s1, " 1 , 2 , 3"]
2.5.0 :003 > Rake::Task['ws'].invoke(' 1 ', ' 2 ', ' 3 ')
[:s1, " 1 "]
[:s2, " 2 "]
[:s3, " 3 "] The simplest solution for command line would be probably just to split by |
You're right. They can be treated as separate issues. UPDATE: New issue reported #260 |
makes sense, at least multiple arguments in command line will work consistently with each other :) though not in a way I would expect and not consistently with rails console |
Keep in mind part of the parsing is done by ruby with how it makes For example, forget about
So given that rake uses |
Yeah, sure I understand it. The 2 cases you provided are identical from the OS point of view since they are basically:
But things can be a bit more complex too. One can write for example
and get in
And a question arises whether this case should be treated as if multiple arguments are provided or as if it is a single argument (since there are explicit quotes). Currently rake treats it as there are multiple arguments:
$ rake "ws[' 1 , 2 , 3']"
[:s1, "' 1"]
[:s2, "2"]
[:s3, "3'"]
$ rake "ws[' 1 , 2 , 3']"
[:s1, "' 1"] And even a more intersting case is where the number of quotes is not even: $ ruby argv_inspector.rb "task[' 1 , '2 , 3 ']"
["task[' 1 , '2 , 3 ']"] I have no idea how this should be interpreted :) (and it's just a simple case with 1,2,3 but there can be a complex sentence - e.g. there could be a task to send an email that accepts email body as an argument). But still it would be great if a simple case with a single argument would be processed correctly without cutting off any characters - just like in the console. |
Having a simple rake task:
I get following results when run this task in command line:
While when the task is being invoked in rails console everything works as expected:
Again, it is definitely not the OS who is responsible for that trimming, since it shouldn't trim anything between quote marks. And besides it can be easily tested this way:
then in command line:
Rake version 12.0.0
some investigation on the issue https://stackoverflow.com/questions/45622716/rake-removes-trailing-whitespaces-from-parameters-how-to-prevent#answer-45623592
The text was updated successfully, but these errors were encountered: