diff --git a/core/src/main/java/org/jruby/util/Sprintf.java b/core/src/main/java/org/jruby/util/Sprintf.java index e5b8b4aa6fc..216ffeacdec 100644 --- a/core/src/main/java/org/jruby/util/Sprintf.java +++ b/core/src/main/java/org/jruby/util/Sprintf.java @@ -374,10 +374,12 @@ private static boolean rubySprintfToBuffer(ByteList buf, CharSequence charFormat // MRI doesn't flag it as an error if width is given multiple // times as a number (but it does for *) number = 0; - for ( ; offset < length && isDigit(fchar = format[offset]); offset++) { - number = extendWidth(args, number, fchar); + { // MRI: GETNUM macro + for (; offset < length && isDigit(fchar = format[offset]); offset++) { + number = extendWidth(args, number, fchar); + } + checkOffset(args, offset, length, ERR_MALFORMED_NUM); } - checkOffset(args,offset,length,ERR_MALFORMED_NUM); if (fchar == '$') { if (arg != null) { raiseArgumentError(args,"value given twice - " + number + "$"); @@ -434,10 +436,12 @@ private static boolean rubySprintfToBuffer(ByteList buf, CharSequence charFormat checkOffset(args,++offset,length,ERR_MALFORMED_STAR_NUM); mark = offset; number = 0; - for ( ; offset < length && isDigit(fchar = format[offset]); offset++) { - number = extendWidth(args,number,fchar); + { // MRI: GETNUM macro + for (; offset < length && isDigit(fchar = format[offset]); offset++) { + number = extendWidth(args, number, fchar); + } + checkOffset(args, offset, length, ERR_MALFORMED_STAR_NUM); } - checkOffset(args,offset,length,ERR_MALFORMED_STAR_NUM); if (fchar == '$') { precision = args.getNthInt(number); if (precision < 0) { diff --git a/test/mri/excludes/TestSprintf.rb b/test/mri/excludes/TestSprintf.rb index c7e138d302d..2ab75b8c2c9 100644 --- a/test/mri/excludes/TestSprintf.rb +++ b/test/mri/excludes/TestSprintf.rb @@ -8,3 +8,4 @@ exclude :test_named_untyped, "needs investigation" exclude :test_named_untyped_enc, "needs investigation" exclude :test_nan, "needs investigation" +exclude :test_star, "differing error message somewhere deep in GETNUM macro from MRI and our equivalents"