* 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
This commit is contained in:
parent
c51b9bacec
commit
7145ec7bb2
@ -1,3 +1,8 @@
|
|||||||
|
Thu Nov 10 21:05:03 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* lib/shellwords.rb: fix for blank but not empty string.
|
||||||
|
fixed: [ruby-dev:27663]
|
||||||
|
|
||||||
Wed Nov 9 08:39:38 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Wed Nov 9 08:39:38 2005 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* lib/shellwords.rb: refactored. [ruby-core:06581]
|
* lib/shellwords.rb: refactored. [ruby-core:06581]
|
||||||
|
@ -26,22 +26,18 @@ module Shellwords
|
|||||||
# See the +Shellwords+ module documentation for an example.
|
# See the +Shellwords+ module documentation for an example.
|
||||||
#
|
#
|
||||||
def shellwords(line)
|
def shellwords(line)
|
||||||
line = String.new(line) rescue
|
|
||||||
raise(ArgumentError, "Argument must be a string")
|
|
||||||
words = []
|
words = []
|
||||||
field = ''
|
field = ''
|
||||||
last = 0
|
word = sq = dq = esc = garbage = sep = nil
|
||||||
sep = nil
|
line.scan(/\G\s*(?>([^\s\\\'\"]+)|'([^\']*)'|"((?:[^\"\\]|\\.)*)"|(\\.?)|(\S))(\s|\z)?/m) do
|
||||||
line.scan(/\G\s*(?:([^\s\\\'\"]+)|'([^\']*)'|"((?:[^\"\\]|\\.)*)"|(\\.?))(\s+|\z)?/m) do
|
|word, sq, dq, esc, garbage, sep|
|
||||||
last = $~.end(0)
|
raise ArgumentError, "Unmatched double quote: #{line.inspect}" if garbage
|
||||||
sep = $~.begin(5)
|
field << (word || sq || (dq || esc).gsub(/\\(?=.)/, ''))
|
||||||
field << ($1 || $2 || ($3 || $4).gsub(/\\(?=.)/, ''))
|
|
||||||
if sep
|
if sep
|
||||||
words << field
|
words << field
|
||||||
field = ''
|
field = ''
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
raise ArgumentError, "Unmatched double quote: #{line}" if line[last]
|
|
||||||
words
|
words
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user