Skip to content

Commit 49a74b9

Browse files
committed
Kernel#sprintf must raise ArgumentError on dangling '%' chars in format string since Ruby 2.5
1 parent 617e783 commit 49a74b9

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

core/src/main/java/org/jruby/util/Sprintf.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public class Sprintf {
9090
private static final String ERR_MALFORMED_DOT_NUM = "malformed format string - %.[0-9]";
9191
private static final String ERR_MALFORMED_STAR_NUM = "malformed format string - %*[0-9]";
9292
private static final String ERR_ILLEGAL_FORMAT_CHAR = "illegal format character - %";
93+
private static final String ERR_INCOMPLETE_FORMAT_SPEC = "incomplete format specifier; use %%%% (double %%) instead";
9394
private static final String ERR_MALFORMED_NAME = "malformed name - unmatched parenthesis";
9495

9596
private static final ThreadLocal<Map<Locale, NumberFormat>> LOCALE_NUMBER_FORMATS = new ThreadLocal<Map<Locale, NumberFormat>>();
@@ -1413,6 +1414,7 @@ else if ((flags & FLAG_MINUS) != 0) {
14131414
if (incomplete) {
14141415
if (flags == FLAG_NONE) {
14151416
// dangling '%' char
1417+
if (format[length - 1] == '%') raiseArgumentError(args,ERR_INCOMPLETE_FORMAT_SPEC);
14161418
buf.append('%');
14171419
} else {
14181420
raiseArgumentError(args,ERR_ILLEGAL_FORMAT_CHAR);

0 commit comments

Comments
 (0)