Actions
Bug #20438
closedString format "%\n" and "%\0" does not raise format error
Bug #20438:
String format "%\n" and "%\0" does not raise format error
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 3.3.0 (2023-12-25 revision 5124f9ac75) +YJIT +MN [arm64-darwin22]
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
Actions