Report abuse

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
diff --git a/kernel/common/sprintf.rb b/kernel/common/sprintf.rb
index 8eade59..d63eb25 100644
--- a/kernel/common/sprintf.rb
+++ b/kernel/common/sprintf.rb
@@ -179,8 +179,10 @@ module Rubinius
             raise ArgumentError, "invalid type (only Fixnum allowed)"
           end

-          val = (2**(2.size * 8)) + val
-          if !flags[:zero] and !precision
+          if !flags[:space] and !flags[:plus]
+            val = (2**(2.size * 8)) + val
+          end
+          if !flags[:zero] and !precision and !flags[:space] and !flags[:plus]
             ret = "..#{pad(val, width, precision)}"
           else
             ret = pad(val, width, precision)
@@ -283,8 +285,11 @@ module Rubinius
       ret = val.to_s
       modded_width = width.to_i + (flags[:plus] ? 1 : 0)
       width = nil if modded_width <= val.to_s.size
-      sign = plus_char
-
+      if ret[0] != ?-
+        sign = plus_char
+      else
+        sign = ""
+      end
       if precision || flags[:zero]
         ret.gsub!("..", "")
       end