зеркало из https://github.com/github/ruby.git
* 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
This commit is contained in:
Родитель
38ce9797c1
Коммит
6ba4bd5858
|
@ -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.
|
||||
|
|
4
pack.c
4
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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
Загрузка…
Ссылка в новой задаче