sprintf.c: don't raise "too many arguments" errors when $DEBUG is set

[Feature #22136]

This is as far as I can tell the only method that changes its behavior
in debug mode, and that's all but helpful because it might cause
the program to abort.

Usually when you run a program with $DEBUG set, it is to find some
error that may have been swallowed, so aside from the extra output
you would expect Ruby to behave the same than in normal mode.
This commit is contained in:
Jean Boussier committed 2026-07-10 07:34:42 +02:00
1 parent b9be3d6b6d
commit 64450290f3
2 files changed
+13 -12
Notes: git 2026-07-10 05:35:12 +00:00

No files matched your search

+13 -11
View File
@@ -67,18 +67,20 @@ describe "String#%" do
end
end
it "raises an ArgumentError for unused arguments when $DEBUG is true" do
begin
old_debug = $DEBUG
$DEBUG = true
s = $stderr
$stderr = IOStub.new
ruby_version_is ""..."4.1" do
it "raises an ArgumentError for unused arguments when $DEBUG is true" do
begin
old_debug = $DEBUG
$DEBUG = true
s = $stderr
$stderr = IOStub.new
-> { "" % [1, 2, 3] }.should.raise(ArgumentError)
-> { "%s" % [1, 2, 3] }.should.raise(ArgumentError)
ensure
$DEBUG = old_debug
$stderr = s
-> { "" % [1, 2, 3] }.should.raise(ArgumentError)
-> { "%s" % [1, 2, 3] }.should.raise(ArgumentError)
ensure
$DEBUG = old_debug
$stderr = s
end
end
end
-1
View File
@@ -947,7 +947,6 @@ rb_str_format(int argc, const VALUE *argv, VALUE fmt)
*/
if (posarg >= 0 && nextarg < argc && !(argc == 2 && RB_TYPE_P(argv[1], T_HASH))) {
const char *mesg = "too many arguments for format string";
if (RTEST(ruby_debug)) rb_raise(rb_eArgError, "%s", mesg);
if (RTEST(ruby_verbose)) rb_warn("%s", mesg);
}
rb_str_resize(result, blen);