summaryrefslogtreecommitdiff
path: root/chef-config
diff options
context:
space:
mode:
authornimesh-msys <nimesh.patni@msystechnologies.com>2018-07-23 16:17:20 +0530
committernimesh-msys <nimesh.patni@msystechnologies.com>2018-07-23 17:27:13 +0530
commit4b5f73868ea131780ac29c3b8d6dfb7506b02afa (patch)
tree49e0308aa32cb62cfd3a3c50b925eaa41d0dbb62 /chef-config
parent1bd742d6833a27c685907c414c3bb9c16d543bdd (diff)
downloadchef-4b5f73868ea131780ac29c3b8d6dfb7506b02afa.tar.gz
Handling quotes in Windows Task commands
- Added a custom method to split the command and its arguments - Checked the beaviour when they are inclusive of single/double quotes - Added their specs to test the functionality. Covered a [tpec](https://github.com/chef/chef/compare/sp/7413) Fixes: MSYS-855 Signed-off-by: nimesh-msys <nimesh.patni@msystechnologies.com>
Diffstat (limited to 'chef-config')
-rw-r--r--chef-config/lib/chef-config/path_helper.rb23
1 files changed, 23 insertions, 0 deletions
diff --git a/chef-config/lib/chef-config/path_helper.rb b/chef-config/lib/chef-config/path_helper.rb
index 053c7a3c32..f1dc47a489 100644
--- a/chef-config/lib/chef-config/path_helper.rb
+++ b/chef-config/lib/chef-config/path_helper.rb
@@ -295,5 +295,28 @@ module ChefConfig
ChefConfig.logger.error("Cannot write to a SIP Path on OS X 10.11+")
false
end
+
+ # Splits a string into an array of tokens as commands and arguments
+ #
+ # str = 'command with "some arguments"'
+ # split_args(str) => ["command", "with", "\"some arguments\""]
+ #
+ def self.split_args(line)
+ cmd_args = []
+ field = ""
+ line.scan(/\s*(?>([^\s\\"]+|"([^"]*)"|'([^']*)')|(\S))(\s|\z)?/m) do |word, within_dq, within_sq, esc, sep|
+
+ # Appand the string with Word & Escape Character
+ field << (word || esc.gsub(/\\(.)/, '\\1'))
+
+ # Re-build the field when any whitespace character or
+ # End of string is encountered
+ if sep
+ cmd_args << field
+ field = ""
+ end
+ end
+ cmd_args
+ end
end
end