mruby-sprintf: raise ArgumentError for % at the bottom

This commit is contained in:
Yukihiro "Matz" Matsumoto
2024-05-03 07:46:45 +09:00
parent 4801a424a3
commit aea3e7aedd
2 changed files with 4 additions and 6 deletions
+4 -1
View File
@@ -607,7 +607,10 @@ mrb_str_format(mrb_state *mrb, mrb_int argc, const mrb_value *argv, mrb_value fm
for (t = p; t < end && *t != '%'; t++)
;
if (t + 1 == end) t++;
if (t + 1 == end) {
/* % at the bottom */
mrb_raise(mrb, E_ARGUMENT_ERROR, "incomplete format specifier; use %% (double %) instead");
}
PUSH(p, t - p);
if (t >= end)
goto sprint_exit; /* end of fmt string */
-5
View File
@@ -90,8 +90,3 @@ assert("String#% invalid format") do
"%?" % ""
end
end
assert("String#% invalid format shared substring") do
fmt = ("x"*30+"%!")[0...-1]
assert_equal fmt, sprintf(fmt, "")
end