From 9f1d389d7e9fd6c6cbb9248f6579befb23b28ecc Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 10 Nov 2005 12:05:57 +0000 Subject: * 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 --- lib/shellwords.rb | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'lib/shellwords.rb') 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 -- cgit