mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-12 16:01:27 +08:00
bugfix: avoid to escape html
This commit is contained in:
@@ -28,8 +28,19 @@ func Dump2JSON(data interface{}, path string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
log.Info().Str("path", path).Msg("dump data to json")
|
log.Info().Str("path", path).Msg("dump data to json")
|
||||||
file, _ := json.MarshalIndent(data, "", " ")
|
|
||||||
err = os.WriteFile(path, file, 0o644)
|
// init json encoder
|
||||||
|
buffer := new(bytes.Buffer)
|
||||||
|
encoder := json.NewEncoder(buffer)
|
||||||
|
encoder.SetEscapeHTML(false)
|
||||||
|
encoder.SetIndent("", " ")
|
||||||
|
|
||||||
|
err = encoder.Encode(data)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = os.WriteFile(path, buffer.Bytes(), 0o644)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error().Err(err).Msg("dump json path failed")
|
log.Error().Err(err).Msg("dump json path failed")
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -587,11 +587,11 @@ func (s *stepFromHAR) makeRequestBody(entry *Entry) error {
|
|||||||
s.Request.Body = body
|
s.Request.Body = body
|
||||||
} else if strings.HasPrefix(mimeType, "application/x-www-form-urlencoded") {
|
} else if strings.HasPrefix(mimeType, "application/x-www-form-urlencoded") {
|
||||||
// post form
|
// post form
|
||||||
var paramsList []string
|
paramsMap := make(map[string]string)
|
||||||
for _, param := range entry.Request.PostData.Params {
|
for _, param := range entry.Request.PostData.Params {
|
||||||
paramsList = append(paramsList, fmt.Sprintf("%s=%s", param.Name, param.Value))
|
paramsMap[param.Name] = param.Value
|
||||||
}
|
}
|
||||||
s.Request.Body = strings.Join(paramsList, "&")
|
s.Request.Body = paramsMap
|
||||||
} else if strings.HasPrefix(mimeType, "text/plain") {
|
} else if strings.HasPrefix(mimeType, "text/plain") {
|
||||||
// post raw data
|
// post raw data
|
||||||
s.Request.Body = entry.Request.PostData.Text
|
s.Request.Body = entry.Request.PostData.Text
|
||||||
|
|||||||
@@ -12,5 +12,6 @@ var (
|
|||||||
MarshalIndent = json.MarshalIndent
|
MarshalIndent = json.MarshalIndent
|
||||||
Unmarshal = json.Unmarshal
|
Unmarshal = json.Unmarshal
|
||||||
NewDecoder = json.NewDecoder
|
NewDecoder = json.NewDecoder
|
||||||
|
NewEncoder = json.NewEncoder
|
||||||
Get = json.Get
|
Get = json.Get
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user