1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/shellwords.rb: Turn on frozen-string-literal after fixing

shellsplit.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53066 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
knu 2015-12-13 02:43:56 +00:00
parent 373489bb4e
commit fdfb8804c0
2 changed files with 8 additions and 3 deletions

View file

@ -1,3 +1,8 @@
Sun Dec 13 11:38:12 2015 Akinori MUSHA <knu@iDaemons.org>
* lib/shellwords.rb: Turn on frozen-string-literal after fixing
shellsplit.
Sun Dec 13 10:44:44 2015 Martin Duerst <duerst@it.aoyama.ac.jp> Sun Dec 13 10:44:44 2015 Martin Duerst <duerst@it.aoyama.ac.jp>
* KNOWNBUGS.rb: Fixed typo, made more explicit [ci skip] * KNOWNBUGS.rb: Fixed typo, made more explicit [ci skip]

View file

@ -1,4 +1,4 @@
# frozen-string-literal: false # frozen-string-literal: true
## ##
# == Manipulates strings like the UNIX Bourne shell # == Manipulates strings like the UNIX Bourne shell
# #
@ -70,14 +70,14 @@ module Shellwords
# argv #=> ["here", "are", "two words"] # argv #=> ["here", "are", "two words"]
def shellsplit(line) def shellsplit(line)
words = [] words = []
field = '' field = String.new
line.scan(/\G\s*(?>([^\s\\\'\"]+)|'([^\']*)'|"((?:[^\"\\]|\\.)*)"|(\\.?)|(\S))(\s|\z)?/m) do line.scan(/\G\s*(?>([^\s\\\'\"]+)|'([^\']*)'|"((?:[^\"\\]|\\.)*)"|(\\.?)|(\S))(\s|\z)?/m) do
|word, sq, dq, esc, garbage, sep| |word, sq, dq, esc, garbage, sep|
raise ArgumentError, "Unmatched double quote: #{line.inspect}" if garbage raise ArgumentError, "Unmatched double quote: #{line.inspect}" if garbage
field << (word || sq || (dq || esc).gsub(/\\(.)/, '\\1')) field << (word || sq || (dq || esc).gsub(/\\(.)/, '\\1'))
if sep if sep
words << field words << field
field = '' field = String.new
end end
end end
words words