diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-11-10 12:05:57 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2005-11-10 12:05:57 +0000 |
commit | 7145ec7bb2a5d5efaead6ec523c105837397c3ff (patch) | |
tree | 5adf0e8473d1a521900053a9c1b7d3f766cca8a9 /lib/shellwords.rb | |
parent | c51b9bacec5d007931185cca0d4f5e3a93213b16 (diff) | |
download | ruby-7145ec7bb2a5d5efaead6ec523c105837397c3ff.tar.gz |
* lib/shellwords.rb: fix for blank but not empty string.
fixed: [ruby-dev:27663]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9521 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib/shellwords.rb')
-rw-r--r-- | lib/shellwords.rb | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/lib/shellwords.rb b/lib/shellwords.rb index 055a6a5be2..1d97cd62f2 100644 --- a/lib/shellwords.rb +++ b/lib/shellwords.rb @@ -26,22 +26,18 @@ module Shellwords # See the +Shellwords+ module documentation for an example. # def shellwords(line) - line = String.new(line) rescue - raise(ArgumentError, "Argument must be a string") words = [] field = '' - last = 0 - sep = nil - line.scan(/\G\s*(?:([^\s\\\'\"]+)|'([^\']*)'|"((?:[^\"\\]|\\.)*)"|(\\.?))(\s+|\z)?/m) do - last = $~.end(0) - sep = $~.begin(5) - field << ($1 || $2 || ($3 || $4).gsub(/\\(?=.)/, '')) + word = sq = dq = esc = garbage = sep = nil + line.scan(/\G\s*(?>([^\s\\\'\"]+)|'([^\']*)'|"((?:[^\"\\]|\\.)*)"|(\\.?)|(\S))(\s|\z)?/m) do + |word, sq, dq, esc, garbage, sep| + raise ArgumentError, "Unmatched double quote: #{line.inspect}" if garbage + field << (word || sq || (dq || esc).gsub(/\\(?=.)/, '')) if sep words << field field = '' end end - raise ArgumentError, "Unmatched double quote: #{line}" if line[last] words end |