summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-04-10 22:33:58 +0000
committerdrbrain <drbrain@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-04-10 22:33:58 +0000
commit6ba4bd5858753c1aff9d11cfa7c478b9616c109a (patch)
tree4fea4bdc94488c12c11a02d8e3a79c5804d6724f
parent38ce9797c1b0b5b89cbff9bde72a50fa55f4f335 (diff)
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35292 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog8
-rw-r--r--pack.c4
-rw-r--r--test/ruby/test_pack.rb35
3 files changed, 47 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 6ad9c40bd8..73c86bef12 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+Wed Apr 11 07:33:13 2012 Eric Hodel <drbrain@segment7.net>
+
+ * 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@segment7.net>
* string.c (rb_str_tr): Documented use of \ to escape characters.
diff --git a/pack.c b/pack.c
index 78789889de..4a2d246174 100644
--- a/pack.c
+++ b/pack.c
@@ -1026,6 +1026,8 @@ pack_pack(VALUE ary, VALUE fmt)
break;
default:
+ rb_warning("unknown pack directive '%c' in '%s'",
+ type, RSTRING_PTR(fmt));
break;
}
}
@@ -2143,6 +2145,8 @@ pack_unpack(VALUE str, VALUE fmt)
break;
default:
+ rb_warning("unknown unpack directive '%c' in '%s'",
+ type, RSTRING_PTR(fmt));
break;
}
}
diff --git a/test/ruby/test_pack.rb b/test/ruby/test_pack.rb
index c862215cb4..e623a69cbf 100644
--- a/test/ruby/test_pack.rb
+++ b/test/ruby/test_pack.rb
@@ -651,4 +651,39 @@ class TestPack < Test::Unit::TestCase
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