Merge pull request #1323 from bbx-winner/fix-escape-html

bugfix: avoid to escape html; empty base_url
This commit is contained in:
debugtalk
2022-05-31 15:17:03 +08:00
committed by GitHub
17 changed files with 39 additions and 20 deletions

View File

@@ -1,5 +1,9 @@
# Release History # Release History
## v4.1.1 (2022-05-31)
- fix: failed to build debugtalk.go without go.mod
- fix: avoid to escape from html special characters like '&'
## v4.1.0 (2022-05-29) ## v4.1.0 (2022-05-29)
- feat: add `wiki` sub-command to open httprunner website - feat: add `wiki` sub-command to open httprunner website

View File

@@ -1,5 +1,5 @@
{ {
"project_name": "demo-empty-project", "project_name": "demo-empty-project",
"create_time": "2022-05-31T15:05:51.196187+08:00", "create_time": "2022-05-31T15:05:51.196187+08:00",
"hrp_version": "v4.1.0" "hrp_version": "v4.1.1"
} }

View File

@@ -1,5 +1,5 @@
{ {
"project_name": "demo-with-go-plugin", "project_name": "demo-with-go-plugin",
"create_time": "2022-05-31T15:05:49.894029+08:00", "create_time": "2022-05-31T15:05:49.894029+08:00",
"hrp_version": "v4.1.0" "hrp_version": "v4.1.1"
} }

View File

@@ -1,4 +1,4 @@
# NOTE: Generated By hrp v4.1.0, DO NOT EDIT! # NOTE: Generated By hrp v4.1.1, DO NOT EDIT!
import logging import logging
import time import time

View File

@@ -1,5 +1,5 @@
{ {
"project_name": "demo-with-py-plugin", "project_name": "demo-with-py-plugin",
"create_time": "2022-05-31T15:05:50.036068+08:00", "create_time": "2022-05-31T15:05:50.036068+08:00",
"hrp_version": "v4.1.0" "hrp_version": "v4.1.1"
} }

View File

@@ -1,5 +1,5 @@
{ {
"project_name": "demo-without-plugin", "project_name": "demo-without-plugin",
"create_time": "2022-05-31T15:05:51.066376+08:00", "create_time": "2022-05-31T15:05:51.066376+08:00",
"hrp_version": "v4.1.0" "hrp_version": "v4.1.1"
} }

View File

@@ -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

View File

@@ -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

View File

@@ -118,7 +118,7 @@ func TestMakeTestCaseFromHAR(t *testing.T) {
if !assert.Equal(t, map[string]interface{}{"foo1": "HDnY8", "foo2": 12.3}, tCase.TestSteps[1].Request.Body) { if !assert.Equal(t, map[string]interface{}{"foo1": "HDnY8", "foo2": 12.3}, tCase.TestSteps[1].Request.Body) {
t.Fatal() t.Fatal()
} }
if !assert.Equal(t, "foo1=HDnY8&foo2=12.3", tCase.TestSteps[2].Request.Body) { if !assert.Equal(t, map[string]string{"foo1": "HDnY8", "foo2": "12.3"}, tCase.TestSteps[2].Request.Body) {
t.Fatal() t.Fatal()
} }
@@ -264,7 +264,7 @@ func TestMakeRequestDataParams(t *testing.T) {
t.Fatal() t.Fatal()
} }
if !assert.Equal(t, "a=1&b=2", step.Request.Body) { if !assert.Equal(t, map[string]string{"a": "1", "b": "2"}, step.Request.Body) {
t.Fatal() t.Fatal()
} }
} }

View File

@@ -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
) )

View File

@@ -1,4 +1,4 @@
# NOTE: Generated By hrp v4.1.0, DO NOT EDIT! # NOTE: Generated By hrp v4.1.1, DO NOT EDIT!
import logging import logging
import time import time

View File

@@ -1,4 +1,4 @@
// NOTE: Generated By hrp v4.1.0, DO NOT EDIT! // NOTE: Generated By hrp v4.1.1, DO NOT EDIT!
package main package main
import ( import (
@@ -12,5 +12,5 @@ func main() {
fungo.Register("SetupHookExample", SetupHookExample) fungo.Register("SetupHookExample", SetupHookExample)
fungo.Register("TeardownHookExample", TeardownHookExample) fungo.Register("TeardownHookExample", TeardownHookExample)
fungo.Register("GetUserAgent", GetUserAgent) fungo.Register("GetUserAgent", GetUserAgent)
fungo.Serve() fungo.Serve()
} }

View File

@@ -1 +1 @@
v4.1.0 v4.1.1

View File

@@ -7,4 +7,4 @@ import (
//go:embed VERSION //go:embed VERSION
var VERSION string var VERSION string
const HttpRunnerMinVersion = "v4.0.0-beta" const HttpRunnerMinVersion = "v4.1.0"

View File

@@ -145,7 +145,10 @@ func (r *requestBuilder) prepareUrlParams(stepVariables map[string]interface{})
log.Error().Err(err).Msg("parse request url failed") log.Error().Err(err).Msg("parse request url failed")
return err return err
} }
baseURL := stepVariables["base_url"].(string) var baseURL string
if stepVariables["base_url"] != nil {
baseURL = stepVariables["base_url"].(string)
}
rawUrl := buildURL(baseURL, convertString(requestUrl)) rawUrl := buildURL(baseURL, convertString(requestUrl))
// prepare request params // prepare request params

View File

@@ -1,4 +1,4 @@
__version__ = "v4.1.0" __version__ = "v4.1.1"
__description__ = "One-stop solution for HTTP(S) testing." __description__ = "One-stop solution for HTTP(S) testing."

View File

@@ -1,6 +1,6 @@
[tool.poetry] [tool.poetry]
name = "httprunner" name = "httprunner"
version = "v4.1.0" version = "v4.1.1"
description = "One-stop solution for HTTP(S) testing." description = "One-stop solution for HTTP(S) testing."
license = "Apache-2.0" license = "Apache-2.0"
readme = "README.md" readme = "README.md"