Skip to content

Commit

Permalink
expression: make a copy when retrieving json path expression from cac…
Browse files Browse the repository at this point in the history
…he (#38285)

ref #38230
  • Loading branch information
xiongjiwei authored Oct 2, 2022
1 parent 9657c9e commit 51a6684
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion types/json_path_expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ type JSONPathExpression struct {
flags jsonPathExpressionFlag
}

func (pe JSONPathExpression) clone() JSONPathExpression {
legs := make([]jsonPathLeg, len(pe.legs))
copy(legs, pe.legs)
return JSONPathExpression{legs: legs, flags: pe.flags}
}

var peCache JSONPathExpressionCache

type jsonPathExpressionKey string
Expand Down Expand Up @@ -362,7 +368,7 @@ func ParseJSONPathExpr(pathExpr string) (JSONPathExpression, error) {
val, ok := peCache.cache.Get(jsonPathExpressionKey(pathExpr))
if ok {
peCache.mu.Unlock()
return val.(JSONPathExpression), nil
return val.(JSONPathExpression).clone(), nil
}
peCache.mu.Unlock()

Expand Down

0 comments on commit 51a6684

Please sign in to comment.