Skip to content

Commit

Permalink
ADD string implement for mysql unsafe mode.
Browse files Browse the repository at this point in the history
ADD string implement for mysql unsafe mode.
  • Loading branch information
karminski committed Jan 19, 2024
1 parent aff138c commit 2059426
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/utils/parser/sql/escaper.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ func reflectVariableToString(variable interface{}) (string, error) {
if errInReflect != nil {
return "", errInReflect
}
finalString += subVarInString
finalString += "'" + subVarInString + "'"
}
return "(" + finalString + ")", nil
return finalString, nil
}

return "", errors.New("invalied array type inputed")
Expand Down
12 changes: 12 additions & 0 deletions src/utils/parser/sql/escaper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,15 @@ func TestEscapePostgresSQLInStatementQueryInIntString(t *testing.T) {
assert.Equal(t, []interface{}{"a", "b", "c"}, usedArgs, "the usedArgs should be equal")
assert.Equal(t, "select * from users where id in ($1, $2, $3)", escapedSQL, "the token should be equal")
}

func TestEscapeMySQLSQLInStatementQueryInIntStringInUnsafeMode(t *testing.T) {
sql_1 := `select * from users where id in ({{multiselect1.value.map(b => Number(b))}})`
args := map[string]interface{}{
`multiselect1.value.map(b => Number(b))`: []interface{}{"a", "b", "c"},
}
sqlEscaper := NewSQLEscaper(resourcelist.TYPE_MYSQL_ID)
escapedSQL, usedArgs, errInEscape := sqlEscaper.EscapeSQLActionTemplate(sql_1, args, false)
assert.Nil(t, errInEscape)
assert.Equal(t, []interface{}{}, usedArgs, "the usedArgs should be equal")
assert.Equal(t, "select * from users where id in ('a', 'b', 'c')", escapedSQL, "the token should be equal")
}

0 comments on commit 2059426

Please sign in to comment.