# Sprintf bug?

**URL:** <https://rubytalk.org/t/sprintf-bug/44185>\
**Category:** ruby-talk\
**Created:** [1 February 2008 03:53 UTC](https://rubytalk.org/t/sprintf-bug/44185 "2008-02-01T03:53:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Daniel\_DeLorme](https://avatars.discourse-cdn.com/v4/letter/d/9d8465/32.png) [@Daniel\_DeLorme](https://rubytalk.org/u/Daniel_DeLorme)\
**Post date:** [1 February 2008 03:53 UTC](https://rubytalk.org/t/sprintf-bug/44185/1 "2008-02-01T03:53:12Z")

</div>

I've just stumbled across the following:

machine1$ ruby -ve 'printf("(%\*-s)\n", 10,"hello")'  
ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-freebsd6]  
(hello )

machine2$ ruby -ve 'printf("(%\*-s)\n", 10,"hello")'  
ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-freebsd6]  
-e:1:in `printf': flag after width (ArgumentError)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from -e:1

I can fix it by changing the pattern to "%-\*s", but is that a bug in patchlevel 111 or is it a "bugfix" for a syntax that was never supposed to be valid? And if the second case, what is the point of making things more restrictive?

Daniel

---

<div class="post-metadata">

**Author:** ![Robert\_K1](https://yyz1.discourse-cdn.com/flex029/user_avatar/rubytalk.org/robert_k1/32/1830_2.png) [@Robert\_K1](https://rubytalk.org/u/Robert_K1)\
**Post date:** [1 February 2008 09:08 UTC](https://rubytalk.org/t/sprintf-bug/44185/2 "2008-02-01T09:08:21Z")

</div>

> I've just stumbled across the following:
> 
> machine1$ ruby -ve 'printf("(%\*-s)\n", 10,"hello")'  
> ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-freebsd6]  
> (hello )
> 
> machine2$ ruby -ve 'printf("(%\*-s)\n", 10,"hello")'  
> ruby 1.8.6 (2007-09-24 patchlevel 111) [i386-freebsd6]  
> -e:1:in `printf': flag after width (ArgumentError)  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from -e:1
> 
> I can fix it by changing the pattern to "%-\*s", but is that a bug in  
> patchlevel 111 or is it a "bugfix" for a syntax that was never supposed  
> to be valid?

AFAIK valid syntax always has been this:

irb(main):002:0\> sprintf "%\*s", 10, "hello"  
=\> " hello"  
irb(main):003:0\> sprintf "%-\*s", 10, "hello"  
=\> "hello "

So, it's a bugfix.

> And if the second case, what is the point of making things  
> more restrictive?

I do not understand the question: if it is a bug fix then the new  
behavior is the one that was originally intended. Code that employs  
other syntax is simply broken.

Cheers

robert

> **···**
>
> 2008/2/1, Daniel DeLorme \<dan-ml@dan42.com\>:
> 
> --  
> use.inject do |as, often| as.you\_can - without end
