导出和记录属性的时候,替换特殊字符串
This commit is contained in:
@@ -24,6 +24,7 @@ func (sdk *SDK) GetLogItem(uid, event string, property map[string]any, timezone
|
|||||||
} else {
|
} else {
|
||||||
et = gtime.Now()
|
et = gtime.Now()
|
||||||
}
|
}
|
||||||
|
safeProperty(property)
|
||||||
pstr, err := json.Marshal(property)
|
pstr, err := json.Marshal(property)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
g.Log().Errorf(ctx, "GetLogItem Fail ! json marshal property err: %v", err)
|
g.Log().Errorf(ctx, "GetLogItem Fail ! json marshal property err: %v", err)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -15,6 +16,7 @@ import (
|
|||||||
"github.com/gogf/gf/v2/net/gclient"
|
"github.com/gogf/gf/v2/net/gclient"
|
||||||
"github.com/gogf/gf/v2/os/gfile"
|
"github.com/gogf/gf/v2/os/gfile"
|
||||||
"github.com/gogf/gf/v2/os/gtime"
|
"github.com/gogf/gf/v2/os/gtime"
|
||||||
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
type sendBody struct {
|
type sendBody struct {
|
||||||
@@ -66,6 +68,16 @@ var (
|
|||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var safePropertyRE = regexp.MustCompile(`["'\\\/]`)
|
||||||
|
|
||||||
|
func safeProperty(property map[string]any) {
|
||||||
|
for k, v := range property {
|
||||||
|
if _, ok := v.(string); ok {
|
||||||
|
property[k] = safePropertyRE.ReplaceAllString(gconv.String(v), "*")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func getLocationMapValue(key string) *time.Location {
|
func getLocationMapValue(key string) *time.Location {
|
||||||
// 1. 先尝试读
|
// 1. 先尝试读
|
||||||
value, loaded := locationMap.Load(key)
|
value, loaded := locationMap.Load(key)
|
||||||
@@ -278,6 +290,7 @@ func (sdk *SDK) Log(uid, event string, property map[string]any, timezone string,
|
|||||||
if len(property) == 0 {
|
if len(property) == 0 {
|
||||||
property = map[string]any{"ts": gtime.Now().Timestamp()}
|
property = map[string]any{"ts": gtime.Now().Timestamp()}
|
||||||
}
|
}
|
||||||
|
safeProperty(property)
|
||||||
var et *gtime.Time
|
var et *gtime.Time
|
||||||
if len(customEventTime) > 0 {
|
if len(customEventTime) > 0 {
|
||||||
et = gtime.NewFromTime(customEventTime[0])
|
et = gtime.NewFromTime(customEventTime[0])
|
||||||
|
|||||||
Reference in New Issue
Block a user