Project

General

Profile

Actions

Bug #20438

closed

String format "%\n" and "%\0" does not raise format error

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:117619]

Description

"%" % 1 raises incomplete format specifier; use %% (double %) instead
"%=" % 1 raises malformed format string - %=.
But "%\n" % 1 "%\0" % 1 does not raise error.
In sprintf.c, \n and \0 are explicitly accepted. Is this expected?

Some other language are:
Perl: Warns Invalid conversion in printf. Just prints. "%d% " → "1% "
Python: Error ValueError: unsupported format character '?' (0xa) with print("%\n" % 123)
PHP: Error Unknown format specifier with sprintf("%\n", 3)
C, C++: Warns incomplete format specifier. "%\n" → "\n", "%" → "", "% " → ""

sprintf("%f%\n",x) and "%f%\n" % x is used in some codes https://github.com/search?q=language%3ARuby+%22f%25%5Cn%22&type=code


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
Has duplicate Ruby master - Bug #20439: Invalid string format with n$ flag is ignored in some caseClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0