remove usage of gconv.Unsafe* functions internally to avoid unexpected errors

This commit is contained in:
John Guo
2021-09-14 19:30:20 +08:00
parent 99b6085235
commit 727f58a24b
32 changed files with 63 additions and 77 deletions

View File

@ -9,7 +9,6 @@ package gbase64
import (
"encoding/base64"
"github.com/gogf/gf/util/gconv"
"io/ioutil"
)
@ -27,7 +26,7 @@ func EncodeString(src string) string {
// EncodeToString encodes bytes to string with BASE64 algorithm.
func EncodeToString(src []byte) string {
return gconv.UnsafeBytesToStr(Encode(src))
return string(Encode(src))
}
// EncryptFile encodes file content of <path> using BASE64 algorithms.
@ -55,7 +54,7 @@ func EncodeFileToString(path string) (string, error) {
if err != nil {
return "", err
}
return gconv.UnsafeBytesToStr(content), nil
return string(content), nil
}
// MustEncodeFileToString encodes file content of <path> to string using BASE64 algorithms.
@ -103,7 +102,7 @@ func MustDecodeString(data string) []byte {
// DecodeString decodes string with BASE64 algorithm.
func DecodeToString(data string) (string, error) {
b, err := DecodeString(data)
return gconv.UnsafeBytesToStr(b), err
return string(b), err
}
// MustDecodeToString decodes string with BASE64 algorithm.

View File

@ -12,7 +12,6 @@ import (
"github.com/gogf/gf/encoding/gxml"
"github.com/gogf/gf/encoding/gyaml"
"github.com/gogf/gf/internal/json"
"github.com/gogf/gf/util/gconv"
)
// ========================================================================
@ -50,7 +49,7 @@ func (j *Json) MustToJson() []byte {
}
func (j *Json) MustToJsonString() string {
return gconv.UnsafeBytesToStr(j.MustToJson())
return string(j.MustToJson())
}
func (j *Json) MustToJsonIndent() []byte {
@ -62,7 +61,7 @@ func (j *Json) MustToJsonIndent() []byte {
}
func (j *Json) MustToJsonIndentString() string {
return gconv.UnsafeBytesToStr(j.MustToJsonIndent())
return string(j.MustToJsonIndent())
}
// ========================================================================
@ -96,7 +95,7 @@ func (j *Json) MustToXml(rootTag ...string) []byte {
}
func (j *Json) MustToXmlString(rootTag ...string) string {
return gconv.UnsafeBytesToStr(j.MustToXml(rootTag...))
return string(j.MustToXml(rootTag...))
}
func (j *Json) MustToXmlIndent(rootTag ...string) []byte {
@ -108,7 +107,7 @@ func (j *Json) MustToXmlIndent(rootTag ...string) []byte {
}
func (j *Json) MustToXmlIndentString(rootTag ...string) string {
return gconv.UnsafeBytesToStr(j.MustToXmlIndent(rootTag...))
return string(j.MustToXmlIndent(rootTag...))
}
// ========================================================================
@ -135,7 +134,7 @@ func (j *Json) MustToYaml() []byte {
}
func (j *Json) MustToYamlString() string {
return gconv.UnsafeBytesToStr(j.MustToYaml())
return string(j.MustToYaml())
}
// ========================================================================
@ -162,7 +161,7 @@ func (j *Json) MustToToml() []byte {
}
func (j *Json) MustToTomlString() string {
return gconv.UnsafeBytesToStr(j.MustToToml())
return string(j.MustToToml())
}
// ========================================================================
@ -192,5 +191,5 @@ func (j *Json) MustToIni() []byte {
// MustToIniString .
func (j *Json) MustToIniString() string {
return gconv.UnsafeBytesToStr(j.MustToIni())
return string(j.MustToIni())
}