Skip to content

Commit

Permalink
Use proper constructor for regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
jeschkies committed Nov 13, 2023
1 parent cc2246c commit c5d0f56
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions pkg/logql/syntax/serialize.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package syntax
import (
"fmt"
"io"
"regexp"
"time"

jsoniter "github.com/json-iterator/go"
Expand Down Expand Up @@ -550,28 +549,29 @@ func decodeLogRange(iter *jsoniter.Iterator) (*LogRange, error) {
}

func decodeLabelReplace(iter *jsoniter.Iterator) (*LabelReplaceExpr, error) {
expr := &LabelReplaceExpr{}
var err error
var left SampleExpr
var dst, src, replacement, regex string

for f := iter.ReadObject(); f != ""; f = iter.ReadObject() {
switch f {
case "inner":
expr.Left, err = decodeSample(iter)
left, err = decodeSample(iter)
if err != nil {
return nil, err
}
case "dst":
expr.Dst = iter.ReadString()
dst = iter.ReadString()
case "src":
expr.Src = iter.ReadString()
src = iter.ReadString()
case "replacement":
expr.Replacement = iter.ReadString()
replacement = iter.ReadString()
case "regexp":
expr.Regex = iter.ReadString()
if expr.Regex != "" {
expr.Re, err = regexp.Compile(expr.Regex)
}
regex = iter.ReadString()
}
}

return expr, err
return mustNewLabelReplaceExpr(left, dst, replacement, src, regex), nil
}

func decodeLiteral(iter *jsoniter.Iterator) (*LiteralExpr, error) {
Expand Down

0 comments on commit c5d0f56

Please sign in to comment.