@@ -17,11 +17,11 @@ func Append(b []byte, v interface{}, flags int) []byte {
17
17
case bool :
18
18
return appendBool (b , v )
19
19
case int32 :
20
- return strconv . AppendInt (b , int64 (v ), 10 )
20
+ return appendInt (b , int64 (v ))
21
21
case int64 :
22
- return strconv . AppendInt (b , v , 10 )
22
+ return appendInt (b , v )
23
23
case int :
24
- return strconv . AppendInt (b , int64 (v ), 10 )
24
+ return appendInt (b , int64 (v ))
25
25
case float32 :
26
26
return appendFloat (b , float64 (v ), flags , 32 )
27
27
case float64 :
@@ -60,6 +60,15 @@ func appendBool(dst []byte, v bool) []byte {
60
60
return append (dst , "FALSE" ... )
61
61
}
62
62
63
+ func appendInt (dst []byte , v int64 ) []byte {
64
+ // To avoid accidental comments which can lead to SQL injection, put a space before
65
+ // negative numbers immediately following a minus sign.
66
+ if v < 0 && len (dst ) > 0 && dst [len (dst )- 1 ] == '-' {
67
+ dst = append (dst , ' ' )
68
+ }
69
+ return strconv .AppendInt (dst , v , 10 )
70
+ }
71
+
63
72
func appendFloat (dst []byte , v float64 , flags int , bitSize int ) []byte {
64
73
if hasFlag (flags , arrayFlag ) {
65
74
return appendFloat2 (dst , v , flags )
@@ -80,8 +89,18 @@ func appendFloat(dst []byte, v float64, flags int, bitSize int) []byte {
80
89
if hasFlag (flags , quoteFlag ) {
81
90
return append (dst , "'-Infinity'" ... )
82
91
}
92
+ // To avoid accidental comments which can lead to SQL injection, put a space before
93
+ // negative numbers immediately following a minus sign.
94
+ if v < 0 && len (dst ) > 0 && dst [len (dst )- 1 ] == '-' {
95
+ dst = append (dst , ' ' )
96
+ }
83
97
return append (dst , "-Infinity" ... )
84
98
default :
99
+ // To avoid accidental comments which can lead to SQL injection, put a space before
100
+ // negative numbers immediately following a minus sign.
101
+ if v < 0 && len (dst ) > 0 && dst [len (dst )- 1 ] == '-' {
102
+ dst = append (dst , ' ' )
103
+ }
85
104
return strconv .AppendFloat (dst , v , 'f' , - 1 , bitSize )
86
105
}
87
106
}
0 commit comments