From c5d0f56013c7d6721c6a6ceac3279618f423a6a2 Mon Sep 17 00:00:00 2001 From: Karsten Jeschkies Date: Mon, 13 Nov 2023 14:34:13 +0100 Subject: [PATCH] Use proper constructor for regexp --- pkg/logql/syntax/serialize.go | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/logql/syntax/serialize.go b/pkg/logql/syntax/serialize.go index 8829cc60709a9..5ce19c2e140c7 100644 --- a/pkg/logql/syntax/serialize.go +++ b/pkg/logql/syntax/serialize.go @@ -3,7 +3,6 @@ package syntax import ( "fmt" "io" - "regexp" "time" jsoniter "github.com/json-iterator/go" @@ -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) {