From 917474d56b4a7ff8d1a316d65120bd1b07680560 Mon Sep 17 00:00:00 2001 From: "Thomas E. Enebo" Date: Thu, 2 Nov 2023 17:12:50 -0400 Subject: [PATCH] need proper ruby exceptions when passing invalid encoding to format strings encoding for %c --- core/src/main/java/org/jruby/util/Sprintf.java | 7 ++++--- spec/tags/ruby/core/kernel/sprintf_tags.txt | 2 -- spec/tags/ruby/core/string/modulo_tags.txt | 1 - 3 files changed, 4 insertions(+), 6 deletions(-) delete mode 100644 spec/tags/ruby/core/kernel/sprintf_tags.txt delete mode 100644 spec/tags/ruby/core/string/modulo_tags.txt diff --git a/core/src/main/java/org/jruby/util/Sprintf.java b/core/src/main/java/org/jruby/util/Sprintf.java index aca521e7efc..4b07298ce40 100644 --- a/core/src/main/java/org/jruby/util/Sprintf.java +++ b/core/src/main/java/org/jruby/util/Sprintf.java @@ -599,6 +599,7 @@ private static void rubySprintfToBuffer(final ByteList buf, final CharSequence c case 'c': { arg = args.getArg(); + ThreadContext context = runtime.getCurrentContext(); int c; int n; IRubyObject tmp = arg.checkStringType(); @@ -623,19 +624,19 @@ private static void rubySprintfToBuffer(final ByteList buf, final CharSequence c } if ((flags & FLAG_WIDTH) == 0) { buf.ensure(buf.length() + n); - EncodingUtils.encMbcput(c, buf.unsafeBytes(), buf.realSize(), encoding); + EncodingUtils.encMbcput(context, c, buf.unsafeBytes(), buf.realSize(), encoding); buf.realSize(buf.realSize() + n); } else if ((flags & FLAG_MINUS) != 0) { buf.ensure(buf.length() + n); - EncodingUtils.encMbcput(c, buf.unsafeBytes(), buf.realSize(), encoding); + EncodingUtils.encMbcput(context, c, buf.unsafeBytes(), buf.realSize(), encoding); buf.realSize(buf.realSize() + n); buf.fill(' ', width - 1); } else { buf.fill(' ', width - 1); buf.ensure(buf.length() + n); - EncodingUtils.encMbcput(c, buf.unsafeBytes(), buf.realSize(), encoding); + EncodingUtils.encMbcput(context, c, buf.unsafeBytes(), buf.realSize(), encoding); buf.realSize(buf.realSize() + n); } offset++; diff --git a/spec/tags/ruby/core/kernel/sprintf_tags.txt b/spec/tags/ruby/core/kernel/sprintf_tags.txt deleted file mode 100644 index 588543ed749..00000000000 --- a/spec/tags/ruby/core/kernel/sprintf_tags.txt +++ /dev/null @@ -1,2 +0,0 @@ -fails:Kernel#sprintf %c raises error when a codepoint isn't representable in an encoding of a format string -fails:Kernel.sprintf %c raises error when a codepoint isn't representable in an encoding of a format string diff --git a/spec/tags/ruby/core/string/modulo_tags.txt b/spec/tags/ruby/core/string/modulo_tags.txt deleted file mode 100644 index ea022223d56..00000000000 --- a/spec/tags/ruby/core/string/modulo_tags.txt +++ /dev/null @@ -1 +0,0 @@ -fails:String#% %c raises error when a codepoint isn't representable in an encoding of a format string