Project

General

Profile

Actions

Bug #22087

closed

Octal format specifier in alternatve form ignores zero precision if value is zero

Bug #22087: Octal format specifier in alternatve form ignores zero precision if value is zero

Added by Earlopain (Earlopain _) 15 days ago. Updated 15 days ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 4.1.0dev (2026-05-29T14:34:40Z master 7a07a54298) +PRISM [x86_64-linux]
[ruby-core:125592]

Description

For integer types, it is documented that zero as a value results in empty output:
https://docs.ruby-lang.org/en/4.0/language/format_specifications_rdoc.html#:~:text=If%20the%20precision%20is%200%20and%20the%20value%20is%200%2C%20nothing%20is%20written

This applies when # is not given. But with #, the octal format violates that statement:

pp sprintf("%#.0b", 0) # => ""
pp sprintf("%#.0B", 0) # => ""
pp sprintf("%#.0x", 0) # => ""
pp sprintf("%#.0X", 0) # => ""
pp sprintf("%#.0o", 0) # => "0"
Actions

Also available in: PDF Atom