Skip to content

Commit ae64f9d

Browse files
authored
fix unquoted json passed to lua args (#146)
1 parent 54cdf69 commit ae64f9d

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pkg/topology/transport/podexec/cli/tarantoolctl.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"encoding/json"
66
"fmt"
77
"regexp"
8+
"strconv"
89
"strings"
910

1011
"github.com/pkg/errors"
@@ -23,7 +24,7 @@ func (*TarantoolCTL) CreateCommand(lua string, args ...any) (*Command, error) {
2324

2425
tpl := `
2526
local json = require('json')
26-
local args = json.decode('%s')
27+
local args = json.decode(%s)
2728
local func = function(...)
2829
%s
2930
end
@@ -38,9 +39,10 @@ func (*TarantoolCTL) CreateCommand(lua string, args ...any) (*Command, error) {
3839
return nil, err
3940
}
4041

41-
safeLua = fmt.Sprintf(tpl, jsonArgs, lua)
42+
quoted := strconv.Quote(string(jsonArgs))
43+
safeLua = fmt.Sprintf(tpl, quoted, lua)
4244
} else {
43-
safeLua = fmt.Sprintf(tpl, "{}", lua)
45+
safeLua = fmt.Sprintf(tpl, "'{}'", lua)
4446
}
4547

4648
safeLua = strings.ReplaceAll(safeLua, "\t", "")

0 commit comments

Comments
 (0)