[Bug #18956] Negative codepoints are invalid characters
This commit is contained in:
parent
8f4a53d051
commit
d2483393cb
Notes:
git
2022-08-20 10:06:37 +09:00
@ -447,8 +447,8 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
|
||||
goto format_s1;
|
||||
}
|
||||
else {
|
||||
c = NUM2INT(val);
|
||||
n = rb_enc_codelen(c, enc);
|
||||
n = NUM2INT(val);
|
||||
if (n >= 0) n = rb_enc_codelen((c = n), enc);
|
||||
}
|
||||
if (n <= 0) {
|
||||
rb_raise(rb_eArgError, "invalid character");
|
||||
|
@ -368,6 +368,7 @@ class TestSprintf < Test::Unit::TestCase
|
||||
assert_equal(" " * (BSIZ - 1) + "a", sprintf(" " * (BSIZ - 1) + "%-1c", ?a))
|
||||
assert_equal(" " * BSIZ + "a", sprintf("%#{ BSIZ + 1 }c", ?a))
|
||||
assert_equal("a" + " " * BSIZ, sprintf("%-#{ BSIZ + 1 }c", ?a))
|
||||
assert_raise(ArgumentError) { sprintf("%c", -1) }
|
||||
end
|
||||
|
||||
def test_string
|
||||
|
Loading…
x
Reference in New Issue
Block a user