[前][次][番号順一覧][スレッド一覧]

ruby-changes:22238

From: knu <ko1@a...>
Date: Fri, 13 Jan 2012 03:49:41 +0900 (JST)
Subject: [ruby-changes:22238] knu:r34287 (trunk): * lib/shellwords.rb (Shellwords#shellescape): shellescape() now

knu	2012-01-13 03:49:30 +0900 (Fri, 13 Jan 2012)

  New Revision: 34287

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=34287

  Log:
    * lib/shellwords.rb (Shellwords#shellescape): shellescape() now
      stringifies the given object using to_s.
    
    * lib/shellwords.rb (Shellwords#shelljoin): shelljoin() accepts
      non-string objects in the given array, each of which is
      stringified using to_s.

  Modified files:
    trunk/ChangeLog
    trunk/NEWS
    trunk/lib/shellwords.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 34286)
+++ ChangeLog	(revision 34287)
@@ -1,5 +1,12 @@
 Fri Jan 13 03:46:53 2012  Akinori MUSHA  <knu@i...>
 
+	* lib/shellwords.rb (Shellwords#shellescape): shellescape() now
+	  stringifies the given object using to_s.
+
+	* lib/shellwords.rb (Shellwords#shelljoin): shelljoin() accepts
+	  non-string objects in the given array, each of which is
+	  stringified using to_s.
+
 	* lib/shellwords.rb: Fix rdoc markups.
 
 Fri Jan 13 03:38:36 2012  Akinori MUSHA  <knu@i...>
Index: lib/shellwords.rb
===================================================================
--- lib/shellwords.rb	(revision 34286)
+++ lib/shellwords.rb	(revision 34287)
@@ -57,7 +57,8 @@
   end
 
   # Escapes a string so that it can be safely used in a Bourne shell
-  # command line.
+  # command line.  +str+ can be a non-string object that responds to
+  # +to_s+.
   #
   # Note that a resulted string should be used unquoted and is not
   # intended for use in double quotes nor in single quotes.
@@ -77,6 +78,8 @@
   # Multibyte characters are treated as multibyte characters, not
   # bytes.
   def shellescape(str)
+    str = str.to_s
+
     # An empty argument will be skipped, so return empty quotes.
     return "''" if str.empty?
 
@@ -101,7 +104,9 @@
   end
 
   # Builds a command line string from an argument list +array+ joining
-  # all elements escaped for Bourne shell and separated by a space.
+  # all elements escaped for Bourne shell into a single string with
+  # fields separated by a space, where each element is stringified
+  # using +to_s+.
   #
   #   open('|' + Shellwords.join(['grep', pattern, *files])) { |pipe|
   #     # ...
@@ -113,6 +118,11 @@
   #     # ...
   #   }
   #
+  # It is allowed to mix non-string objects in the elements as allowed
+  # in Array#join.
+  #
+  #   output = `#{['ps', '-p', $$].shelljoin}`
+  #
   def shelljoin(array)
     array.map { |arg| shellescape(arg) }.join(' ')
   end
Index: NEWS
===================================================================
--- NEWS	(revision 34286)
+++ NEWS	(revision 34287)
@@ -55,6 +55,11 @@
     * Resolv::DNS#timeouts=
     * Resolv::DNS::Config#timeouts=
 
+* shellwords
+    * Shellwords#shellescape() now stringifies the given object using to_s.
+    * Shellwords#shelljoin() accepts non-string objects in the given
+      array, each of which is stringified using to_s.
+
 === Language changes
 === Compatibility issues (excluding feature bug fixes)
 

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]