@@ -113,6 +113,19 @@ void randomBytesDontCauseExceptionsOrTimeouts() {
113
113
}
114
114
}
115
115
116
+ @ Test
117
+ public void longInStatementDoesntCauseStackOverflow () {
118
+ StringBuilder s = new StringBuilder ("select col from table where col in (" );
119
+ for (int i = 0 ; i < 10000 ; i ++) {
120
+ s .append ("?," );
121
+ }
122
+ s .append ("?)" );
123
+
124
+ String sanitized = SqlStatementSanitizer .create (true ).sanitize (s .toString ()).getFullStatement ();
125
+
126
+ assertThat (sanitized ).isEqualTo ("select col from table where col in (?)" );
127
+ }
128
+
116
129
static class SqlArgs implements ArgumentsProvider {
117
130
118
131
@ Override
@@ -271,7 +284,11 @@ public Stream<? extends Arguments> provideArguments(ExtensionContext context) th
271
284
Arguments .of ("select col from table1 as t1, table2 as t2" , expect ("SELECT" , null )),
272
285
Arguments .of (
273
286
"select col from table where col in (1, 2, 3)" ,
274
- expect ("select col from table where col in (?, ?, ?)" , "SELECT" , "table" )),
287
+ expect ("select col from table where col in (?)" , "SELECT" , "table" )),
288
+ Arguments .of (
289
+ "select 'a' IN(x, 'b') from table where col in (1) and z IN( '3', '4' )" ,
290
+ expect (
291
+ "select ? IN(x, ?) from table where col in (?) and z IN(?)" , "SELECT" , "table" )),
275
292
Arguments .of ("select col from table order by col, col2" , expect ("SELECT" , "table" )),
276
293
Arguments .of ("select ąś∂ń© from źćļńĶ order by col, col2" , expect ("SELECT" , "źćļńĶ" )),
277
294
Arguments .of ("select 12345678" , expect ("select ?" , "SELECT" , null )),
@@ -298,6 +315,9 @@ public Stream<? extends Arguments> provideArguments(ExtensionContext context) th
298
315
"delete from `my table` where something something" , expect ("DELETE" , "my table" )),
299
316
Arguments .of (
300
317
"delete from \" my table\" where something something" , expect ("DELETE" , "my table" )),
318
+ Arguments .of (
319
+ "delete from foo where x IN (1,2,3)" ,
320
+ expect ("delete from foo where x IN (?)" , "DELETE" , "foo" )),
301
321
Arguments .of ("delete from 12345678" , expect ("delete from ?" , "DELETE" , null )),
302
322
Arguments .of ("delete (((" , expect ("delete (((" , "DELETE" , null )),
303
323
@@ -307,6 +327,12 @@ public Stream<? extends Arguments> provideArguments(ExtensionContext context) th
307
327
Arguments .of (
308
328
"update `my table` set answer=42" ,
309
329
expect ("update `my table` set answer=?" , "UPDATE" , "my table" )),
330
+ Arguments .of (
331
+ "update `my table` set answer=42 where x IN('a', 'b') AND y In ('a', 'b')" ,
332
+ expect (
333
+ "update `my table` set answer=? where x IN(?) AND y In (?)" ,
334
+ "UPDATE" ,
335
+ "my table" )),
310
336
Arguments .of (
311
337
"update \" my table\" set answer=42" ,
312
338
expect ("update \" my table\" set answer=?" , "UPDATE" , "my table" )),
0 commit comments