File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -52,6 +52,12 @@ func cleanSpaces(input string) string {
5252 return result
5353}
5454
55+ func cleanWhereCond (input string ) string {
56+ re := regexp .MustCompile (`(?i)where\s*and|where or` )
57+ cleanedInput := re .ReplaceAllString (input , "WHERE" )
58+ return cleanedInput
59+ }
60+
5561func sanitizeInjection (input string ) string {
5662 re := regexp .MustCompile (`(?i)[;]|--|drop\s*table|@@\s*version|insert\s*into|if\s*\(|sleep\s*\(|"|\/\*|\*\/|\\0|\\'|\\"|\\b|\\n|\\r|\\t|\\Z|\\\\|\\%|\\_` )
5763 cleanedInput := re .ReplaceAllString (input , "" )
@@ -239,7 +245,7 @@ func (jql *Json2Sql) GenerateWhere() string {
239245 var sql = ""
240246
241247 if jql .sqlJson .Conditions != nil {
242- sql += " WHERE " + jql .GenerateConditions (* jql .sqlJson .Conditions ... )
248+ sql += cleanWhereCond ( " WHERE " + jql .GenerateConditions (* jql .sqlJson .Conditions ... ) )
243249 }
244250
245251 return sql
Original file line number Diff line number Diff line change @@ -377,6 +377,35 @@ func TestBetweenWithOperand(t *testing.T) {
377377 assert .Equal (t , strings .TrimSpace (strExpected ), strings .TrimSpace (str ))
378378}
379379
380+ func TestWhereIs (t * testing.T ) {
381+ var sqlTest = `
382+ {
383+ "conditions": [
384+ {
385+ "operand": "or",
386+ "clause": "a",
387+ "datatype": "STRING",
388+ "operator": "is not null",
389+ "value": null
390+ },
391+ {
392+ "operand": "and",
393+ "clause": "b",
394+ "datatype": "STRING",
395+ "operator": "is null",
396+ "value": null
397+ }
398+ ]
399+ }
400+ `
401+
402+ strExpected := `WHERE a IS NOT NULL AND b IS NULL`
403+ jql , _ := NewJson2Sql ([]byte (sqlTest ), & Json2SqlConf {})
404+ str := jql .GenerateWhere ()
405+
406+ assert .Equal (t , strings .TrimSpace (strExpected ), strings .TrimSpace (str ))
407+ }
408+
380409func TestCompositeWithoutOperand (t * testing.T ) {
381410 var sqlTest = `
382411 {
You can’t perform that action at this time.
0 commit comments