Skip to content

Commit

Permalink
Kernel#sprintf must raise ArgumentError on dangling '%' chars in form…
Browse files Browse the repository at this point in the history
…at string since Ruby 2.5
  • Loading branch information
nomadium committed Mar 25, 2018
1 parent 617e783 commit 49a74b9
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions core/src/main/java/org/jruby/util/Sprintf.java
Expand Up @@ -90,6 +90,7 @@ public class Sprintf {
private static final String ERR_MALFORMED_DOT_NUM = "malformed format string - %.[0-9]";
private static final String ERR_MALFORMED_STAR_NUM = "malformed format string - %*[0-9]";
private static final String ERR_ILLEGAL_FORMAT_CHAR = "illegal format character - %";
private static final String ERR_INCOMPLETE_FORMAT_SPEC = "incomplete format specifier; use %%%% (double %%) instead";
private static final String ERR_MALFORMED_NAME = "malformed name - unmatched parenthesis";

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

0 comments on commit 49a74b9

Please sign in to comment.