Skip to content

Commit 58c8c8b

Browse files
committed
[GR-20446] Raise argument error when not enough printf arguments.
PullRequest: truffleruby/1245
2 parents 3f0a2d9 + 1821572 commit 58c8c8b

File tree

8 files changed

+4
-24
lines changed

8 files changed

+4
-24
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ Bug fixes:
6060
* Fixed `String#capitalize!` for strings that weren't full ASCII.
6161
* Fixed enumeration issue in `ENV.{select, filter}`.
6262
* Fixed `Complex` and `Rational` should be frozen after initializing.
63+
* Fixed `printf` should raise error when not enough arguments for positional argument.
6364

6465
Compatibility:
6566

spec/tags/core/file/printf_tags.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
fails:File#printf other formats c raises ArgumentError if argument is an empty string
22
fails:File#printf other formats c supports Unicode characters
33
fails:File#printf other formats s does not try to convert with to_str
4-
fails:File#printf flags (digit)$ raises exception if argument number is bigger than actual arguments list
54
fails:File#printf flags # applies to format o does nothing for negative argument
65
fails:File#printf flags # applies to formats bBxX does nothing for zero argument
76
fails:File#printf flags # applies to formats aAeEfgG forces a decimal point to be added, even if no digits follow

spec/tags/core/kernel/printf_tags.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,6 @@ fails:Kernel.printf formatting io is specified reference by name %{name} style c
116116
fails:Kernel.printf formatting io is not specified other formats c raises ArgumentError if argument is an empty string
117117
fails:Kernel.printf formatting io is not specified other formats c supports Unicode characters
118118
fails:Kernel.printf formatting io is not specified other formats s does not try to convert with to_str
119-
fails:Kernel.printf formatting io is not specified flags (digit)$ raises exception if argument number is bigger than actual arguments list
120119
fails:Kernel.printf formatting io is not specified flags # applies to format o does nothing for negative argument
121120
fails:Kernel.printf formatting io is not specified flags # applies to formats bBxX does nothing for zero argument
122121
fails:Kernel.printf formatting io is not specified flags # applies to formats aAeEfgG forces a decimal point to be added, even if no digits follow

spec/tags/core/kernel/sprintf_tags.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ fails:Kernel#sprintf raises Encoding::CompatibilityError if both encodings are A
44
fails:Kernel#sprintf other formats c raises ArgumentError if argument is an empty string
55
fails:Kernel#sprintf other formats c supports Unicode characters
66
fails:Kernel#sprintf other formats s does not try to convert with to_str
7-
fails:Kernel#sprintf flags (digit)$ raises exception if argument number is bigger than actual arguments list
87
fails:Kernel#sprintf flags # applies to format o does nothing for negative argument
98
fails:Kernel#sprintf flags # applies to formats bBxX does nothing for zero argument
109
fails:Kernel#sprintf flags # applies to formats aAeEfgG forces a decimal point to be added, even if no digits follow
@@ -21,7 +20,6 @@ fails:Kernel.sprintf raises Encoding::CompatibilityError if both encodings are A
2120
fails:Kernel.sprintf other formats c raises ArgumentError if argument is an empty string
2221
fails:Kernel.sprintf other formats c supports Unicode characters
2322
fails:Kernel.sprintf other formats s does not try to convert with to_str
24-
fails:Kernel.sprintf flags (digit)$ raises exception if argument number is bigger than actual arguments list
2523
fails:Kernel.sprintf flags # applies to format o does nothing for negative argument
2624
fails:Kernel.sprintf flags # applies to formats bBxX does nothing for zero argument
2725
fails:Kernel.sprintf flags # applies to formats aAeEfgG forces a decimal point to be added, even if no digits follow

spec/tags/core/string/modulo_tags.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ fails:String#% other formats c raises ArgumentError if argument is an empty stri
99
fails:String#% other formats c supports Unicode characters
1010
fails:String#% other formats s does not try to convert with to_str
1111
fails:String#% other formats % alone raises an ArgumentError
12-
fails:String#% flags (digit)$ raises exception if argument number is bigger than actual arguments list
1312
fails:String#% flags # applies to format o does nothing for negative argument
1413
fails:String#% flags # applies to formats bBxX does nothing for zero argument
1514
fails:String#% flags # applies to formats aAeEfgG forces a decimal point to be added, even if no digits follow

spec/tags/core/string/percent_tags.txt

Lines changed: 0 additions & 18 deletions
This file was deleted.

spec/tags/library/stringio/printf_tags.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ fails:StringIO#printf formatting other formats c raises ArgumentError if argumen
22
fails:StringIO#printf formatting other formats c supports Unicode characters
33
fails:StringIO#printf formatting other formats s does not try to convert with to_str
44
fails:StringIO#printf formatting other formats % is escaped by %
5-
fails:StringIO#printf formatting flags (digit)$ raises exception if argument number is bigger than actual arguments list
65
fails:StringIO#printf formatting flags # applies to format o does nothing for negative argument
76
fails:StringIO#printf formatting flags # applies to formats bBxX does nothing for zero argument
87
fails:StringIO#printf formatting flags # applies to formats aAeEfgG forces a decimal point to be added, even if no digits follow

src/main/java/org/truffleruby/core/format/printf/PrintfSimpleParser.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,9 @@ public List<SprintfConfig> parse() {
106106
if (config.getAbsoluteArgumentIndex() != null) {
107107
throw new InvalidFormatException("value given twice - " + r.getNumber() + "$");
108108
}
109+
if (arguments.length < r.getNumber()) {
110+
throw new InvalidFormatException("too few arguments");
111+
}
109112
checkPosArg(argType, r.getNumber());
110113
argType = ArgType.NUMBERED;
111114
argTypeSet = true;

0 commit comments

Comments
 (0)