Skip to content

Commit

Permalink
Ignore comments on rule parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
dhaavi committed Apr 12, 2022
1 parent cb9d8ce commit 295efbb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 8 additions & 0 deletions profile/endpoints/endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,14 @@ func parseEndpoint(value string) (endpoint Endpoint, err error) { //nolint:gocog
return nil, fmt.Errorf(`invalid endpoint definition: "%s"`, value)
}

// Remove comment.
for i, field := range fields {
if strings.HasPrefix(field, "#") {
fields = fields[:i]
break
}
}

// any
if endpoint, err = parseTypeAny(fields); endpoint != nil || err != nil {
return
Expand Down
4 changes: 3 additions & 1 deletion profile/endpoints/endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,13 @@ entriesLoop:
// ListEntryValidationRegex is a regex to bullshit check endpoint list entries.
var ListEntryValidationRegex = strings.Join([]string{
`^(\+|\-) `, // Rule verdict.
`(! +)?`, // Invert matching.
`[A-z0-9\.:\-*/]+`, // Entity matching.
`( `, // Start of optional matching.
`[A-z0-9*]+`, // Protocol matching.
`(/[A-z0-9]+(\-[A-z0-9]+)?)?`, // Port and port range matching.
`)?$`, // End of optional matching.
`)?`, // End of optional matching.
`( +#.*)?`, // Optional comment.
}, "")

// ValidateEndpointListConfigOption validates the given value.
Expand Down

0 comments on commit 295efbb

Please sign in to comment.