From a3ca4e2ec90693b5e1c674f8f16936f19ec25478 Mon Sep 17 00:00:00 2001 From: andig Date: Thu, 2 Jan 2025 13:28:04 +0100 Subject: [PATCH] Jq: add quote option (#18009) --- provider/pipeline/pipeline.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/provider/pipeline/pipeline.go b/provider/pipeline/pipeline.go index fd7fc68d73..1e2e1bc1a7 100644 --- a/provider/pipeline/pipeline.go +++ b/provider/pipeline/pipeline.go @@ -21,6 +21,7 @@ type Pipeline struct { re *regexp.Regexp jq *gojq.Query allowEmpty bool + quote bool dflt string unpack string decode string @@ -28,6 +29,7 @@ type Pipeline struct { type Settings struct { AllowEmpty bool + Quote bool Regex string Default string Jq string @@ -39,6 +41,7 @@ func New(log *util.Logger, cc Settings) (*Pipeline, error) { p := &Pipeline{ log: log, allowEmpty: cc.AllowEmpty, + quote: cc.Quote, } var err error @@ -191,6 +194,9 @@ func (p *Pipeline) Process(in []byte) ([]byte, error) { } if p.jq != nil { + if p.quote { + b = []byte(fmt.Sprintf("%q", string(b))) + } v, err := jq.Query(p.jq, b) if err != nil { return b, backoff.Permanent(err)