Backport #7990
closedprintf and sprintf integer conversion failure of string for "08" and "09"
Description
Happens consistently. Converting var to int explicitly first or removing the leading "0" allows it to work fine. Example:
2.0.0-p0 :004 > (0..10).each {|x|
2.0.0-p0 :005 > x=x.to_s
2.0.0-p0 :006?> printf("%s,%02d;", x, x)
2.0.0-p0 :007?> }
0,00;1,01;2,02;3,03;4,04;5,05;6,06;7,07;8,08;9,09;10,10; => 0..10
2.0.0-p0 :008 > (0..10).each {|x|
2.0.0-p0 :009 > x = sprintf("%02d", x)
2.0.0-p0 :010?> printf("%s,%02d;", x, x)
2.0.0-p0 :011?> }
00,00;01,01;02,02;03,03;04,04;05,05;06,06;07,07;ArgumentError: invalid value for Integer(): "08"
from (irb):10:in printf' from (irb):10:in
block in irb_binding'
from (irb):8:in each' from (irb):8 from /usr/local/rvm/rubies/ruby-2.0.0-p0/bin/irb:16:in
'
2.0.0-p0 :012 > printf("%02d", "09")
ArgumentError: invalid value for Integer(): "09"
from (irb):12:in printf' from (irb):12 from /usr/local/rvm/rubies/ruby-2.0.0-p0/bin/irb:16:in
'
Running on x64 centos 6.3
#rvm list
rvm rubies
=* ruby-2.0.0-p0 [ x86_64 ]
Updated by drbrain (Eric Hodel) about 11 years ago
- Status changed from Open to Rejected
=begin
A number with a leading 0 is considered octal, see ((%ri ruby:syntax/literals%)), so this is expected behavior.
PS: This is tracker is for backports of fixed issues. You should file new issues here: https://bugs.ruby-lang.org/projects/ruby-trunk/issues/new
=end