[ruby-core:117620] [Ruby master Bug#20439] Invalid string format with n$ flag is ignored in some case

Issue #20439 has been reported by tompng (tomoya ishida). ---------------------------------------- Bug #20439: Invalid string format with n$ flag is ignored in some case https://bugs.ruby-lang.org/issues/20439 * Author: tompng (tomoya ishida) * Status: Open * ruby -v: ruby 3.3.0 (2023-12-25 revision 5124f9ac75) +YJIT +MN [arm64-darwin22] * Backport: 3.0: UNKNOWN, 3.1: UNKNOWN, 3.2: UNKNOWN, 3.3: UNKNOWN ---------------------------------------- String format including n$ flag and no type specifier raises ArgumentError ~~~ruby "%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. ~~~ruby "%1$\n" % 1 #=> "%\n" "%1$\0" % 1 #=> "%\u0000" "%1$" % 1 #=> "%" ~~~ -- https://bugs.ruby-lang.org/
participants (1)
-
tompng (tomoya ishida)