mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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
2 changed files with 10 additions and 9 deletions
|
@ -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>
|
||||
|
||||
* lib/shellwords.rb: refactored. [ruby-core:06581]
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue