Skip to content

Commit

Permalink
fix: unescape filter argument before running filter (#3683)
Browse files Browse the repository at this point in the history
* fix: unescape filter argument before running filter

* add test

* remove old test
  • Loading branch information
mathnogueira authored Feb 26, 2024
1 parent 8f2f2dc commit d19b5cd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 1 deletion.
2 changes: 1 addition & 1 deletion server/expression/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func (e Executor) executeFilter(input value.Value, filter *Filter) (value.Value,
return value.Nil, err
}

args = append(args, resolvedArg.Value().Value)
args = append(args, resolvedArg.UnescappedString())
}

newValue, err := executeFilter(input, filter.Name, args)
Expand Down
15 changes: 15 additions & 0 deletions server/expression/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ func TestStringInterpolationExecution(t *testing.T) {
}

func TestFilterExecution(t *testing.T) {
jsonResponseSpan := traces.Span{
ID: id.NewRandGenerator().SpanID(),
Attributes: traces.NewAttributes(),
}

jsonResponseSpan.Attributes.Set("tracetest.response.body", `{"results":[{"count(*)":{"result":3}}]}`)

testCases := []executorTestCase{
{
Name: "should_extract_id_from_json",
Expand Down Expand Up @@ -216,6 +223,14 @@ func TestFilterExecution(t *testing.T) {
Query: `'{ "array": [1, 2, 5] }' | json_path '$.array[*]' | get_index 'last' = 5`,
ShouldPass: true,
},
{
Name: "should_unescape_filter_arg",
Query: `attr:tracetest.response.body | json_path '$.results[0][\'count(*)\'].result' = 3`,
ShouldPass: true,
AttributeDataStore: expression.AttributeDataStore{
Span: jsonResponseSpan,
},
},
}

executeTestCases(t, testCases)
Expand Down
8 changes: 8 additions & 0 deletions server/expression/value/value.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,11 @@ func (v Value) String() string {

return v.Value().Value
}

func (v Value) UnescappedString() string {
output := v.String()
output = strings.ReplaceAll(output, `\'`, `'`)
output = strings.ReplaceAll(output, `\"`, `"`)

return output
}

0 comments on commit d19b5cd

Please sign in to comment.