option import fix, switched to using shellwords
git-svn-id: file:///home/svn/incoming/trunk@2748 4d416f70-5f16-0410-b530-b9f4589650daunstable
parent
2a1cbf38e1
commit
e5186edd13
|
@ -32,10 +32,10 @@ class DataStore < Hash
|
|||
# Figure out the deliminter, default to space.
|
||||
delim = /\s/
|
||||
|
||||
if (option_str.index(','))
|
||||
if (option_str.split('=').length <= 2 or option_str.index(',') != nil)
|
||||
delim = ','
|
||||
end
|
||||
|
||||
|
||||
# Split on the deliminter
|
||||
option_str.split(delim).each { |opt|
|
||||
var, val = opt.split('=')
|
||||
|
@ -44,7 +44,8 @@ class DataStore < Hash
|
|||
if (var == nil or val == nil)
|
||||
var = "unknown" if (!var)
|
||||
|
||||
raise Rex::ArgumentParseError, "Invalid option specified: #{var}", caller
|
||||
raise Rex::ArgumentParseError, "Invalid option specified: #{var}",
|
||||
caller
|
||||
end
|
||||
|
||||
# Store the value
|
||||
|
|
|
@ -149,9 +149,15 @@ protected
|
|||
# Parse a line into an array of arguments
|
||||
#
|
||||
def parse_line(line)
|
||||
line.gsub!("(\r|\n)", '')
|
||||
line.gsub!(/(\r|\n)/, '')
|
||||
|
||||
begin
|
||||
return args = Rex::Parser::Arguments.from_s(line)
|
||||
rescue ArgumentError
|
||||
print_error("Parse error: #{$!}")
|
||||
end
|
||||
|
||||
args = Rex::Parser::Arguments.from_s(line)
|
||||
return []
|
||||
end
|
||||
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require 'shellwords'
|
||||
|
||||
module Rex
|
||||
module Parser
|
||||
|
||||
|
@ -33,18 +35,7 @@ class Arguments
|
|||
# Takes a string and converts it into an array of arguments
|
||||
#
|
||||
def self.from_s(str)
|
||||
# I am the king of sucking at regex.
|
||||
sub = str.gsub(/["](.+?)[^\\]["]/) { |s| s.gsub(/\s/, '__SEP__') }
|
||||
sub.gsub!(/[^\\](["])/) { |s| s[0..0] }
|
||||
sub.gsub!(/(\\")/, '"')
|
||||
|
||||
args = []
|
||||
|
||||
sub.split(/\s/).each { |arg|
|
||||
args << arg.gsub(/__SEP__/, ' ')
|
||||
}
|
||||
|
||||
return args
|
||||
Shellwords.shellwords(str)
|
||||
end
|
||||
|
||||
#
|
||||
|
|
Loading…
Reference in New Issue