[Bug #18955] Check length of argument for %c
in proper encoding
This commit is contained in:
parent
4177f60eed
commit
ce384ef5a9
Notes:
git
2025-04-09 13:49:37 +00:00
@ -441,10 +441,11 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
|
|||||||
|
|
||||||
tmp = rb_check_string_type(val);
|
tmp = rb_check_string_type(val);
|
||||||
if (!NIL_P(tmp)) {
|
if (!NIL_P(tmp)) {
|
||||||
if (rb_enc_strlen(RSTRING_PTR(tmp),RSTRING_END(tmp),enc) != 1) {
|
rb_encoding *valenc = rb_enc_get(tmp);
|
||||||
|
if (rb_enc_strlen(RSTRING_PTR(tmp), RSTRING_END(tmp), valenc) != 1) {
|
||||||
rb_raise(rb_eArgError, "%%c requires a character");
|
rb_raise(rb_eArgError, "%%c requires a character");
|
||||||
}
|
}
|
||||||
c = rb_enc_codepoint_len(RSTRING_PTR(tmp), RSTRING_END(tmp), &n, enc);
|
c = rb_enc_codepoint_len(RSTRING_PTR(tmp), RSTRING_END(tmp), &n, valenc);
|
||||||
RB_GC_GUARD(tmp);
|
RB_GC_GUARD(tmp);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -892,6 +892,8 @@ class TestM17N < Test::Unit::TestCase
|
|||||||
assert_raise(Encoding::CompatibilityError) {
|
assert_raise(Encoding::CompatibilityError) {
|
||||||
"%s%s" % [s("\xc2\xa1"), e("\xc2\xa1")]
|
"%s%s" % [s("\xc2\xa1"), e("\xc2\xa1")]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
"%c" % "\u3042".encode('Windows-31J')
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_sprintf_p
|
def test_sprintf_p
|
||||||
|
Loading…
x
Reference in New Issue
Block a user