[MacRuby] #663: Kernel#sprintf formatting broken on trunk

MacRuby ruby-noreply at macosforge.org
Mon Aug 16 14:13:34 PDT 2010


#663: Kernel#sprintf formatting broken on trunk
-------------------------------------+--------------------------------------
 Reporter:  jordan.breeding@…        |       Owner:  lsansonetti@…        
     Type:  defect                   |      Status:  new                  
 Priority:  blocker                  |   Milestone:  MacRuby 0.6          
Component:  MacRuby                  |    Keywords:                       
-------------------------------------+--------------------------------------

Comment(by watson1978@…):

 I rewrote a patch.
 {{{
 #!diff
 diff --git a/string.c b/string.c
 index 969cc4b..c28c0fb 100644
 --- a/string.c
 +++ b/string.c
 @@ -6495,7 +6495,13 @@ rb_uchar_strtol(UniChar *chars, long chars_len,
 long pos, long *end_offset)
      unum_close(nf);

      if (end_offset != NULL) {
 -       *end_offset = (long)parse_pos;
 +       long offset = (long)pos;
 +       do {
 +           if(!isdigit(chars[offset])) {
 +               break;
 +           }
 +       } while(++offset < parse_pos);
 +       *end_offset = offset;
      }
      return val;
  }
 }}}

 Test Code:
 {{{
 #!ruby
 p sprintf("%06.4d", 2)
 p sprintf("%06.0d", 2)
 p sprintf("%06.04d", 2)
 p sprintf("%+06.04d", 2)
 p sprintf("%-06.04d", 2)
 p sprintf("%25.12d", 2)
 begin
   p sprintf("%06.-4d", 2)
 rescue => e
   p e
 end

 begin
   p sprintf("%06.+4d", 2)
 rescue => e
   p e
 end
 }}}

 Result
 {{{
 $ ruby test.rb
 "  0002"
 "     2"
 "  0002"
 " +0002"
 "0002  "
 "             000000000002"
 #<ArgumentError: flag after width>
 #<ArgumentError: flag after width>

 $ DYLD_LIBRARY_PATH=. ./macruby -I./lib test.rb
 "  0002"
 "     2"
 "  0002"
 " +0002"
 "0002  "
 "             000000000002"
 #<ArgumentError: invalid precision>
 #<ArgumentError: invalid precision>
 }}}

-- 
Ticket URL: <http://www.macruby.org/trac/ticket/663#comment:4>
MacRuby <http://macruby.org/>



More information about the macruby-tickets mailing list