Skip to content

Commit f382307

Browse files
committed
Fix curl data option
1 parent 56fce48 commit f382307

File tree

1 file changed

+15
-7
lines changed

1 file changed

+15
-7
lines changed

transformers/httpie/transformers.go

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ package httpie
33
import (
44
"encoding/json"
55
"errors"
6-
"github.com/dcb9/curl2httpie/curl"
7-
"github.com/dcb9/curl2httpie/httpie"
86
"io/ioutil"
97
"strings"
8+
9+
"github.com/dcb9/curl2httpie/curl"
10+
"github.com/dcb9/curl2httpie/httpie"
1011
)
1112

1213
type Transformer func(cl *httpie.CmdLine, o *curl.Option)
@@ -44,11 +45,18 @@ func Method(cl *httpie.CmdLine, o *curl.Option) {
4445
var ErrUnknownDataType = errors.New("unknown data type")
4546

4647
func Data(cl *httpie.CmdLine, o *curl.Option) {
47-
s := strings.SplitN(o.Arg, "=", 2)
48-
if len(s) == 2 {
49-
i := httpie.NewDataField(s[0], s[1])
50-
cl.AddItem(i)
51-
cl.HasBody = true
48+
args := strings.Split(o.Arg, "&")
49+
var urlEncoded bool
50+
for _, arg := range args {
51+
s := strings.SplitN(arg, "=", 2)
52+
if len(s) == 2 {
53+
i := httpie.NewDataField(s[0], s[1])
54+
cl.AddItem(i)
55+
cl.HasBody = true
56+
urlEncoded = true
57+
}
58+
}
59+
if urlEncoded {
5260
return
5361
}
5462

0 commit comments

Comments
 (0)