mirror of
https://github.com/safing/portmaster
synced 2025-09-02 18:49:14 +00:00
Add endpoint list validation regex and function
This commit is contained in:
parent
0c835dd6f7
commit
2106192633
1 changed files with 22 additions and 0 deletions
|
@ -2,6 +2,7 @@ package endpoints
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -58,6 +59,27 @@ entriesLoop:
|
||||||
return endpoints, nil
|
return endpoints, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ListEntryValidationRegex is a regex to bullshit check endpoint list entries.
|
||||||
|
var ListEntryValidationRegex = strings.Join([]string{
|
||||||
|
`^(\+|\-) `, // Rule verdict.
|
||||||
|
`[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.
|
||||||
|
}, "")
|
||||||
|
|
||||||
|
// ValidateEndpointListConfigOption validates the given value.
|
||||||
|
func ValidateEndpointListConfigOption(value interface{}) error {
|
||||||
|
list, ok := value.([]string)
|
||||||
|
if !ok {
|
||||||
|
return errors.New("invalid type")
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err := ParseEndpoints(list)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// IsSet returns whether the Endpoints object is "set".
|
// IsSet returns whether the Endpoints object is "set".
|
||||||
func (e Endpoints) IsSet() bool {
|
func (e Endpoints) IsSet() bool {
|
||||||
return len(e) > 0
|
return len(e) > 0
|
||||||
|
|
Loading…
Add table
Reference in a new issue