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 | 9f1d389d7e9fd6c6cbb9248f6579befb23b28ecc (patch) | |
| tree | 5adf0e8473d1a521900053a9c1b7d3f766cca8a9 /lib | |
| parent | 821b603285833db76b6c09d571965067a18e18d6 (diff) | |
| download | ruby-9f1d389d7e9fd6c6cbb9248f6579befb23b28ecc.tar.gz ruby-9f1d389d7e9fd6c6cbb9248f6579befb23b28ecc.tar.xz ruby-9f1d389d7e9fd6c6cbb9248f6579befb23b28ecc.zip | |
* lib/shellwords.rb: fix for blank but not empty string.
fixed: [ruby-dev:27663]
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@9521 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
| -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 055a6a5be..1d97cd62f 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 |
