ruby-changes:22522
From: knu <ko1@a...>
Date: Mon, 13 Feb 2012 09:20:52 +0900 (JST)
Subject: [ruby-changes:22522] knu:r34571 (ruby_1_9_3): merge revision(s) 34284:34286:
knu 2012-02-12 16:51:05 +0900 (Sun, 12 Feb 2012) New Revision: 34571 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34571 Log: merge revision(s) 34284:34286: * lib/shellwords.rb: Fix rdoc markups. * lib/shellwords.rb (Shellwords#shellsplit): Fix a bug where consecutive backslashes in double quotes are all removed except the one at the tail. Modified files: branches/ruby_1_9_3/ChangeLog branches/ruby_1_9_3/lib/shellwords.rb branches/ruby_1_9_3/test/test_shellwords.rb branches/ruby_1_9_3/version.h Index: ruby_1_9_3/ChangeLog =================================================================== --- ruby_1_9_3/ChangeLog (revision 34570) +++ ruby_1_9_3/ChangeLog (revision 34571) @@ -1,3 +1,13 @@ +Sun Feb 12 16:50:28 2012 Akinori MUSHA <knu@i...> + + * lib/shellwords.rb: Fix rdoc markups. + +Sun Feb 12 16:50:28 2012 Akinori MUSHA <knu@i...> + + * lib/shellwords.rb (Shellwords#shellsplit): Fix a bug where + consecutive backslashes in double quotes are all removed except + the one at the tail. + Sun Feb 12 16:38:13 2012 Akinori MUSHA <knu@i...> * lib/shellwords.rb (Shellwords#shellescape): Drop the //n flag Index: ruby_1_9_3/lib/shellwords.rb =================================================================== --- ruby_1_9_3/lib/shellwords.rb (revision 34570) +++ ruby_1_9_3/lib/shellwords.rb (revision 34571) @@ -17,25 +17,23 @@ # - Akinori MUSHA <knu@i...> (current maintainer) # module Shellwords - # # Splits a string into an array of tokens in the same way the UNIX # Bourne shell does. # # argv = Shellwords.split('here are "two words"') # argv #=> ["here", "are", "two words"] # - # +String#shellsplit+ is a shorthand for this function. + # String#shellsplit is a shorthand for this function. # # argv = 'here are "two words"'.shellsplit # argv #=> ["here", "are", "two words"] - # def shellsplit(line) words = [] field = '' 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(/\\(?=.)/, '')) + field << (word || sq || (dq || esc).gsub(/\\(.)/, '\\1')) if sep words << field field = '' @@ -52,7 +50,6 @@ alias split shellsplit end - # # Escapes a string so that it can be safely used in a Bourne shell # command line. # @@ -63,7 +60,7 @@ # # ... # } # - # +String#shellescape+ is a shorthand for this function. + # String#shellescape is a shorthand for this function. # # open("| grep #{pattern.shellescape} file") { |pipe| # # ... @@ -73,7 +70,6 @@ # encoding for the shell environment where this string is used. # Multibyte characters are treated as multibyte characters, not # bytes. - # def shellescape(str) # An empty argument will be skipped, so return empty quotes. return "''" if str.empty? @@ -98,7 +94,6 @@ alias escape shellescape end - # # Builds a command line string from an argument list +array+ joining # all elements escaped for Bourne shell and separated by a space. # @@ -106,7 +101,7 @@ # # ... # } # - # +Array#shelljoin+ is a shorthand for this function. + # Array#shelljoin is a shorthand for this function. # # open('|' + ['grep', pattern, *files].shelljoin) { |pipe| # # ... @@ -124,38 +119,32 @@ end class String - # # call-seq: # str.shellsplit => array # # Splits +str+ into an array of tokens in the same way the UNIX - # Bourne shell does. See +Shellwords::shellsplit+ for details. - # + # Bourne shell does. See Shellwords::shellsplit for details. def shellsplit Shellwords.split(self) end - # # call-seq: # str.shellescape => string # # Escapes +str+ so that it can be safely used in a Bourne shell - # command line. See +Shellwords::shellescape+ for details. - # + # command line. See Shellwords::shellescape for details. def shellescape Shellwords.escape(self) end end class Array - # # call-seq: # array.shelljoin => string # # Builds a command line string from an argument list +array+ joining # all elements escaped for Bourne shell and separated by a space. - # See +Shellwords::shelljoin+ for details. - # + # See Shellwords::shelljoin for details. def shelljoin Shellwords.join(self) end Index: ruby_1_9_3/version.h =================================================================== --- ruby_1_9_3/version.h (revision 34570) +++ ruby_1_9_3/version.h (revision 34571) @@ -1,5 +1,5 @@ #define RUBY_VERSION "1.9.3" -#define RUBY_PATCHLEVEL 99 +#define RUBY_PATCHLEVEL 100 #define RUBY_RELEASE_DATE "2012-02-12" #define RUBY_RELEASE_YEAR 2012 Index: ruby_1_9_3/test/test_shellwords.rb =================================================================== --- ruby_1_9_3/test/test_shellwords.rb (revision 34570) +++ ruby_1_9_3/test/test_shellwords.rb (revision 34571) @@ -38,6 +38,15 @@ end end + def test_backslashes + cmdline, expected = [ + %q{/a//b///c////d/////e/ "/a//b///c////d/////e/ "'/a//b///c////d/////e/ '/a//b///c////d/////e/ }, + %q{a/b/c//d//e a/b/c//d//e /a//b///c////d/////e/ a/b/c//d//e } + ].map { |str| str.tr("/", "\\\\") } + + assert_equal [expected], shellwords(cmdline) + end + def test_multibyte_characters # This is not a spec. It describes the current behavior which may # be changed in future. There would be no multibyte character -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/