Skip to content

Commit

Permalink
need proper ruby exceptions when passing invalid encoding to format s…
Browse files Browse the repository at this point in the history
…trings encoding for %c
  • Loading branch information
enebo committed Nov 2, 2023
1 parent f373339 commit 917474d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 6 deletions.
7 changes: 4 additions & 3 deletions core/src/main/java/org/jruby/util/Sprintf.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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++;
Expand Down
2 changes: 0 additions & 2 deletions spec/tags/ruby/core/kernel/sprintf_tags.txt

This file was deleted.

1 change: 0 additions & 1 deletion spec/tags/ruby/core/string/modulo_tags.txt

This file was deleted.

0 comments on commit 917474d

Please sign in to comment.