Project

General

Profile

Actions

Bug #20439

closed

Invalid string format with n$ flag is ignored in some case

Added by tompng (tomoya ishida) 7 months ago. Updated 6 months ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) +YJIT +MN [arm64-darwin22]
[ruby-core:117620]

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 #=> "%"

Related issues 2 (0 open2 closed)

Related to Ruby master - Bug #13315: Single "%" at the end of `printf` format string appears in the resultClosedEregon (Benoit Daloze)Actions
Is duplicate of Ruby master - Bug #20438: String format "%\n" and "%\0" does not raise format errorClosedActions
Actions #1

Updated by nobu (Nobuyoshi Nakada) 7 months ago

  • Is duplicate of Bug #20438: String format "%\n" and "%\0" does not raise format error added
Actions #2

Updated by nobu (Nobuyoshi Nakada) 7 months ago

  • Related to Bug #13315: Single "%" at the end of `printf` format string appears in the result added
Actions #3

Updated by nobu (Nobuyoshi Nakada) 6 months ago

  • Status changed from Open to Closed

Applied in changeset git|31c9a3a1d330606493e5e70aec3cd1a36d8c61a0.


[Bug #20438] Disallow "%\n" and "%\0"

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0