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

ruby-changes:40989

From: normal <ko1@a...>
Date: Sun, 13 Dec 2015 12:17:57 +0900 (JST)
Subject: [ruby-changes:40989] normal:r53068 (trunk): lib/shellwords.rb: do not change API with frozen-string-literal

normal	2015-12-13 12:17:28 +0900 (Sun, 13 Dec 2015)

  New Revision: 53068

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

  Log:
    lib/shellwords.rb: do not change API with frozen-string-literal
    
    This fixes a bug introduced in r53066 when attempting to
    shellescape an empty string.
    
    * lib/shellwords.rb (shellescape): duplicate frozen literal
    * test/test_shellwords.rb (test_stringification): new test

  Modified files:
    trunk/lib/shellwords.rb
    trunk/test/test_shellwords.rb
Index: lib/shellwords.rb
===================================================================
--- lib/shellwords.rb	(revision 53067)
+++ lib/shellwords.rb	(revision 53068)
@@ -125,7 +125,7 @@ module Shellwords https://github.com/ruby/ruby/blob/trunk/lib/shellwords.rb#L125
     str = str.to_s
 
     # An empty argument will be skipped, so return empty quotes.
-    return "''" if str.empty?
+    return "''".dup if str.empty?
 
     str = str.dup
 
Index: test/test_shellwords.rb
===================================================================
--- test/test_shellwords.rb	(revision 53067)
+++ test/test_shellwords.rb	(revision 53068)
@@ -48,8 +48,17 @@ class TestShellwords < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/test_shellwords.rb#L48
   end
 
   def test_stringification
-    assert_equal "3", shellescape(3)
-    assert_equal "ps -p #{$$}", ['ps', '-p', $$].shelljoin
+    three = shellescape(3)
+    assert_equal '3', three
+    assert_not_predicate three, :frozen?
+
+    empty = shellescape('')
+    assert_equal "''", empty
+    assert_not_predicate empty, :frozen?
+
+    joined = ['ps', '-p', $$].shelljoin
+    assert_equal "ps -p #{$$}", joined
+    assert_not_predicate joined, :frozen?
   end
 
   def test_multibyte_characters

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

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