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

ruby-changes:23241

From: drbrain <ko1@a...>
Date: Wed, 11 Apr 2012 07:34:10 +0900 (JST)
Subject: [ruby-changes:23241] drbrain:r35292 (trunk): * pack.c (pack_pack): Warn when an invalid character is found in the

drbrain	2012-04-11 07:33:58 +0900 (Wed, 11 Apr 2012)

  New Revision: 35292

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

  Log:
    * pack.c (pack_pack):  Warn when an invalid character is found in the
      format string when $VERBOSE is true.  [ruby-trunk - Feature #5219]
    * pack.c (pack_unpack):  ditto
    * test/ruby/test_pack.rb (class TestPack):  Test for warnings on
      invalid format characters.

  Modified files:
    trunk/ChangeLog
    trunk/pack.c
    trunk/test/ruby/test_pack.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 35291)
+++ ChangeLog	(revision 35292)
@@ -1,3 +1,11 @@
+Wed Apr 11 07:33:13 2012  Eric Hodel  <drbrain@s...>
+
+	* pack.c (pack_pack):  Warn when an invalid character is found in the
+	  format string when $VERBOSE is true.  [ruby-trunk - Feature #5219]
+	* pack.c (pack_unpack):  ditto
+	* test/ruby/test_pack.rb (class TestPack):  Test for warnings on
+	  invalid format characters.
+
 Wed Apr 11 06:11:10 2012  Eric Hodel  <drbrain@s...>
 
 	* string.c (rb_str_tr):  Documented use of \ to escape characters.
Index: pack.c
===================================================================
--- pack.c	(revision 35291)
+++ pack.c	(revision 35292)
@@ -1026,6 +1026,8 @@
 	    break;
 
 	  default:
+	    rb_warning("unknown pack directive '%c' in '%s'",
+		type, RSTRING_PTR(fmt));
 	    break;
 	}
     }
@@ -2143,6 +2145,8 @@
 	    break;
 
 	  default:
+	    rb_warning("unknown unpack directive '%c' in '%s'",
+		type, RSTRING_PTR(fmt));
 	    break;
 	}
     }
Index: test/ruby/test_pack.rb
===================================================================
--- test/ruby/test_pack.rb	(revision 35291)
+++ test/ruby/test_pack.rb	(revision 35292)
@@ -651,4 +651,39 @@
     assert_nil("".unpack("i") {|x| result = x}, bug4059)
     assert_equal(:ok, result)
   end
+
+  def test_pack_garbage
+    assert_silent do
+      assert_equal "\000", [0].pack("*U")
+    end
+
+    verbose = $VERBOSE
+    $VERBOSE = true
+
+    _, err = capture_io do
+      assert_equal "\000", [0].pack("*U")
+    end
+
+    assert_match %r%unknown pack directive '\*' in '\*U'$%, err
+  ensure
+    $VERBOSE = verbose
+  end
+
+  def test_unpack_garbage
+    assert_silent do
+      assert_equal [0], "\000".unpack("*U")
+    end
+
+    verbose = $VERBOSE
+    $VERBOSE = true
+
+    _, err = capture_io do
+      assert_equal [0], "\000".unpack("*U")
+    end
+
+    assert_match %r%unknown unpack directive '\*' in '\*U'$%, err
+  ensure
+    $VERBOSE = verbose
+  end
+
 end

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

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