| 170 | } |
| 171 | |
| 172 | func TestQuerySanitize(t *testing.T) { |
| 173 | successfulTests := []struct { |
| 174 | query sanitize.Query |
| 175 | args []any |
| 176 | expected string |
| 177 | }{ |
| 178 | { |
| 179 | query: sanitize.Query{Parts: []sanitize.Part{"select 42"}}, |
| 180 | args: []any{}, |
| 181 | expected: `select 42`, |
| 182 | }, |
| 183 | { |
| 184 | query: sanitize.Query{Parts: []sanitize.Part{"select ", 1}}, |
| 185 | args: []any{int64(42)}, |
| 186 | expected: `select 42 `, |
| 187 | }, |
| 188 | { |
| 189 | query: sanitize.Query{Parts: []sanitize.Part{"select ", 1}}, |
| 190 | args: []any{float64(1.23)}, |
| 191 | expected: `select 1.23 `, |
| 192 | }, |
| 193 | { |
| 194 | query: sanitize.Query{Parts: []sanitize.Part{"select ", 1}}, |
| 195 | args: []any{true}, |
| 196 | expected: `select true `, |
| 197 | }, |
| 198 | { |
| 199 | query: sanitize.Query{Parts: []sanitize.Part{"select ", 1}}, |
| 200 | args: []any{[]byte{0, 1, 2, 3, 255}}, |
| 201 | expected: `select '\x00010203ff' `, |
| 202 | }, |
| 203 | { |
| 204 | query: sanitize.Query{Parts: []sanitize.Part{"select ", 1}}, |
| 205 | args: []any{nil}, |
| 206 | expected: `select null `, |
| 207 | }, |
| 208 | { |
| 209 | query: sanitize.Query{Parts: []sanitize.Part{"select ", 1}}, |
| 210 | args: []any{"foobar"}, |
| 211 | expected: `select 'foobar' `, |
| 212 | }, |
| 213 | { |
| 214 | query: sanitize.Query{Parts: []sanitize.Part{"select ", 1}}, |
| 215 | args: []any{"foo'bar"}, |
| 216 | expected: `select 'foo''bar' `, |
| 217 | }, |
| 218 | { |
| 219 | query: sanitize.Query{Parts: []sanitize.Part{"select ", 1}}, |
| 220 | args: []any{`foo\'bar`}, |
| 221 | expected: `select 'foo\''bar' `, |
| 222 | }, |
| 223 | { |
| 224 | query: sanitize.Query{Parts: []sanitize.Part{"insert ", 1}}, |
| 225 | args: []any{time.Date(2020, time.March, 1, 23, 59, 59, 999999999, time.UTC)}, |
| 226 | expected: `insert '2020-03-01 23:59:59.999999Z' `, |
| 227 | }, |
| 228 | { |
| 229 | query: sanitize.Query{Parts: []sanitize.Part{"select 1-", 1}}, |