plugins/logs: Update mechanism to escape field paths (#4756)

Earlier the paths to the field to perform an upsert or
remove operation on were escaped using Go's url.QueryEscape
method. This results in incorrect behavior when the paths contain
a reserved character like ":". This change updates to using
url.PathEscape instead to escape the input and result paths.

Fixes: #4717

Signed-off-by: Ashutosh Narkar <anarkar4387@gmail.com>
This commit is contained in:
Ashutosh Narkar
2022-06-08 22:27:00 -07:00
committed by GitHub
parent b271372338
commit 80eb9be78d
2 changed files with 21 additions and 2 deletions
+2 -2
View File
@@ -70,12 +70,12 @@ func newMaskRule(path string, opts ...maskRuleOption) (*maskRule, error) {
escapedParts := make([]string, len(parts))
for i := range parts {
_, err := url.QueryUnescape(parts[i])
_, err := url.PathUnescape(parts[i])
if err != nil {
return nil, err
}
escapedParts[i] = url.QueryEscape(parts[i])
escapedParts[i] = url.PathEscape(parts[i])
}
modifyFullObj := false
+19
View File
@@ -541,6 +541,25 @@ func TestMaskRuleMask(t *testing.T) {
event: `{"input": {"foo": [{"bar": 1, "baz": 2}]}}`,
exp: `{"input": {"foo": [{"baz": 2}]}, "erased": ["/input/foo/0/bar"]}`,
},
{
note: "erase input: special character in path",
ptr: &maskRule{
OP: maskOPRemove,
Path: "/input/:path",
},
event: `{"input": {"bar": 1, ":path": "token"}}`,
exp: `{"input": {"bar": 1}, "erased": ["/input/:path"]}`,
},
{
note: "upsert input: special character in path",
ptr: &maskRule{
OP: maskOPUpsert,
Path: "/input/:path",
Value: "upserted",
},
event: `{"input": {"bar": 1, ":path": "token"}}`,
exp: `{"input": {"bar": 1, ":path": "upserted"}, "masked": ["/input/:path"]}`,
},
}
for _, tc := range tests {