You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Thanks, this LGTM! I wish there was a comment around the old implementation, because it is more complex than just a gsub. I suspect I was just being conservative.
As far as I understand, you were matching the command part of the commandline, and unescaping the quotes.
It works as long as the command has no quotes in arguments, but fails otherwise.
While testing all this, I noticed another problem. You accept commands either as a big string, or as a string and an array of arguments.
I think the command as a big string is a bad idea. Right now, it makes the command + arguments just fail.
I would just raise an error if the command has spaces in it. However, you might just want to issue a warning, and split it. Here is what I came to, almost verbatim from shellwords :
It looks like I need to look into this a bit more and see what the actual behavior is. From the MS documentation it looks like you can pass arguments either way either via the command line or via arguments, but not both.
commandLine
Defines a required null-terminated string that represents the command to be executed. Typically, the command is specified without any arguments, which are specified separately. However, a user can specify the command line and all of the arguments by using this parameter. If arguments are specified for the commandLine parameter, the args parameter should be NULL.
I have a new duplicate problem. It seems now Gyoku changes quotes to " instead of '.
Forget about the arguments issue, I will open a new one. However, I would like the quote issue to be fixed. As I did not find how to tell Gyoku not to escape quotes, I just gsubed them back :
diff --git a/lib/winrm/winrm_service.rb b/lib/winrm/winrm_service.rb
index 8ce4fc8..3ad8261 100644
--- a/lib/winrm/winrm_service.rb+++ b/lib/winrm/winrm_service.rb@@ -392,7 +392,7 @@ module WinRM
builder.tag! :env, :Envelope, namespaces do |env|
env.tag!(:env, :Header) { |h| h << Gyoku.xml(merge_headers(header,resource_uri_wmi,action_enumerate)) }
env.tag!(:env, :Body) do |env_body|
- env_body.tag!("#{NS_ENUM}:Enumerate") { |en| en << Gyoku.xml(body) }+ env_body.tag!("#{NS_ENUM}:Enumerate") { |en| en << Gyoku.xml(body).gsub('"', "'") }
end
end
Activity
[-]Problem with quotes in run_wql[/-][+]Problem with single quotes in run_wql[/+]Mazwak commentedon May 25, 2015
Here is a patch for the 2 issues, which is more concise :
I didn't test extensively, but it should work.
sneal commentedon May 27, 2015
Thanks, this LGTM! I wish there was a comment around the old implementation, because it is more complex than just a gsub. I suspect I was just being conservative.
Mazwak commentedon May 28, 2015
As far as I understand, you were matching the command part of the commandline, and unescaping the quotes.
It works as long as the command has no quotes in arguments, but fails otherwise.
You can test with :
The second one fails with current code, and works with mine.
I don't know why you excluded the arguments in your fist version.
PS: what is "LGTM" ? Looks good to me ?
Mazwak commentedon May 28, 2015
While testing all this, I noticed another problem. You accept commands either as a big string, or as a string and an array of arguments.
I think the command as a big string is a bad idea. Right now, it makes the command + arguments just fail.
I would just raise an error if the command has spaces in it. However, you might just want to issue a warning, and split it. Here is what I came to, almost verbatim from shellwords :
I just change "^'" and "^"" before parsing, and change them back after. And in run_command :
Ideally, run_command should raise an error, and run_cmd should issue a warning, before splitting the command. All applied, it looks like this :
https://gist.github.com/Mazwak/19f1176a95c0b10f9a89
sneal commentedon Jun 6, 2015
It looks like I need to look into this a bit more and see what the actual behavior is. From the MS documentation it looks like you can pass arguments either way either via the command line or via arguments, but not both.
Mazwak commentedon Feb 18, 2016
I have a new duplicate problem. It seems now Gyoku changes quotes to
"instead of'.Forget about the arguments issue, I will open a new one. However, I would like the quote issue to be fixed. As I did not find how to tell Gyoku not to escape quotes, I just gsubed them back :
Mazwak commentedon Feb 18, 2016
I just read #131 and I don't have time right now for a better patch.
I should work on it soon though.
Mazwak commentedon Feb 19, 2016
After looking more carefully, I think I have a better patch. Instead of bruteforcing Gyoku output, it seems possible to make it not change the input.
I did not test run_cmd, but I did test run_wql.