Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
djaglowski committed Sep 23, 2024
1 parent 7f97a6e commit 6770827
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion pkg/ottl/ottlfuncs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1293,7 +1293,7 @@ Examples:
The `RemoveXML` Converter returns an edited version of an XML string with selected elements removed.

`target` is a Getter that returns a string. This string should be in XML format.
If `target` is not a string, nil, or cannot be parsed as XML, `ParseXML` will return an error.
If `target` is not a string, nil, or is not valid xml, `RemoveXML` will return an error.

`xpath` is a string that specifies an [XPath](https://www.w3.org/TR/1999/REC-xpath-19991116/) expression that
selects one or more elements to remove from the XML document.
Expand Down
16 changes: 8 additions & 8 deletions pkg/ottl/ottlfuncs/func_remove_xml.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ func createRemoveXMLFunction[K any](_ ottl.FunctionContext, oArgs ottl.Arguments
return nil, fmt.Errorf("RemoveXML args must be of type *RemoveXMLAguments[K]")
}

return removeXML(args.Target, args.XPath), nil
return removeXML(args.Target, args.XPath)
}

// removeXML returns a `pcommon.String` that is a result of removing all matching nodes from the target XML.
// removeXML returns a XML formatted string that is a result of removing all matching nodes from the target XML.
// This currently supports removal of elements, attributes, text values, comments, and CharData.
func removeXML[K any](target ottl.StringGetter[K], xPath string) ottl.ExprFunc[K] {
return func(ctx context.Context, tCtx K) (any, error) {
if err := validateXPath(xPath); err != nil {
return nil, err
}
func removeXML[K any](target ottl.StringGetter[K], xPath string) (ottl.ExprFunc[K], error) {
if err := validateXPath(xPath); err != nil {
return nil, err
}

return func(ctx context.Context, tCtx K) (any, error) {
targetVal, err := target.Get(ctx, tCtx)
if err != nil {
return nil, err
Expand All @@ -67,7 +67,7 @@ func removeXML[K any](target ottl.StringGetter[K], xPath string) ottl.ExprFunc[K
})

return top.OutputXML(false), nil
}
}, nil
}

func validateXPath(xPath string) error {
Expand Down
8 changes: 4 additions & 4 deletions pkg/ottl/ottlfuncs/func_remove_xml_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,14 @@ func Test_RemoveXML(t *testing.T) {
}

func Test_RemoveXML_InvalidXML(t *testing.T) {
exprFunc := removeXML(invalidXMLGetter(), "/foo")
_, err := exprFunc(context.Background(), nil)
exprFunc, err := removeXML(invalidXMLGetter(), "/foo")
assert.NoError(t, err)
_, err = exprFunc(context.Background(), nil)
assert.Error(t, err)
}

func Test_RemoveXML_InvalidXPath(t *testing.T) {
exprFunc := removeXML(invalidXPathGetter(), "!")
_, err := exprFunc(context.Background(), nil)
_, err := removeXML(invalidXPathGetter(), "!")
assert.Error(t, err)
}

Expand Down

0 comments on commit 6770827

Please sign in to comment.