Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions models/PrepareRequest.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package models
import (
"bytes"
"encoding/base64"
jsonp "encoding/json"
"errors"
"fmt"
"github.com/wangluozhe/fhttp"
Expand Down Expand Up @@ -139,7 +138,7 @@ func (pr *PrepareRequest) Prepare_body(data *url.Values, files *url.Files, json
}
if data == nil && json != nil {
content_type = "application/json"
json_byte, err := jsonp.Marshal(json)
json_byte, err := utils.Marshal(json)
if err != nil {
return err
}
Expand Down
15 changes: 15 additions & 0 deletions utils/code.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/base64"
"encoding/binary"
"encoding/hex"
"encoding/json"
"errors"
"net/url"
"regexp"
Expand Down Expand Up @@ -179,3 +180,17 @@ func UnEscape(s interface{}) string {
str = DecodeURIComponent(str)
return str
}

// Marshal 避免json.Marshal对 "<", ">", "&" 等字符进行HTML编码
func Marshal(data interface{}) ([]byte, error) {
var buffer bytes.Buffer

encoder := json.NewEncoder(&buffer)

// 禁用HTML转义
encoder.SetEscapeHTML(false)

err := encoder.Encode(data)

return buffer.Bytes(), err
}