Actions
Bug #20439
closedInvalid string format with n$ flag is ignored in some case
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) +YJIT +MN [arm64-darwin22]
Description
String format including n$ flag and no type specifier raises ArgumentError
"%1$ " % 1 # invalid format character - % (ArgumentError)
"%1$," % 1 # malformed format string - %, (ArgumentError)
But when it ends with n$ flag, or the next char to n$ flag is "\n"
or "\0"
, there is no error. Returns string with n$ flag removed.
"%1$\n" % 1 #=> "%\n"
"%1$\0" % 1 #=> "%\u0000"
"%1$" % 1 #=> "%"
Actions
Like0
Like0Like0Like0