Skip to content

Commit d496580

Browse files
committed
fix sprintf WIP
1 parent e7cb465 commit d496580

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/main/java/org/perlonjava/operators/SprintfOperator.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@ public static RuntimeScalar sprintf(RuntimeScalar runtimeScalar, RuntimeList lis
6969
charsWritten += formatted.length();
7070

7171
// Update argument index if not using positional parameters
72-
if (spec.parameterIndex == null && spec.conversionChar != '%') {
72+
// BUT don't update if the specifier was invalid
73+
if (spec.parameterIndex == null && spec.conversionChar != '%' && spec.isValid) {
7374
argIndex = updateArgIndex(spec, argIndex);
7475
}
7576
}
@@ -342,6 +343,9 @@ private static String handleInvalidSpecifier(SprintfFormatParser.FormatSpecifier
342343
WarnDie.warn(new RuntimeScalar(warningMessage), new RuntimeScalar(""));
343344
}
344345

346+
// Don't consume any arguments for invalid specifiers
347+
// The caller should NOT update argIndex for invalid formats
348+
345349
return formatOnly + trailing;
346350
}
347351

0 commit comments

Comments
 (0)