fixing and condition

This commit is contained in:
Mzack9999 2023-06-13 17:24:23 +02:00
parent caedc8afaf
commit a4ef3ea3a9
3 changed files with 21 additions and 2 deletions

View File

@ -89,3 +89,9 @@ func (matcher *Matcher) CompileMatchers() error {
}
return nil
}
// GetType returns the condition type of the matcher
// todo: the field should be exposed natively
func (matcher *Matcher) GetCondition() ConditionType {
return matcher.condition
}

View File

@ -112,7 +112,7 @@ type Matcher struct {
MatchAll bool `yaml:"match-all,omitempty" json:"match-all,omitempty" jsonschema:"title=match all values,description=match all matcher values ignoring condition"`
// cached data for the compiled matcher
condition ConditionType
condition ConditionType // todo: this field should be the one used for overridden marshal ops
matcherType MatcherType
binaryDecoded []string
regexCompiled []*regexp.Regexp

View File

@ -200,9 +200,22 @@ func (request *Request) findMatchesWithReader(reader io.Reader, input, filePath
isResponseDebug := request.options.Options.Debug || request.options.Options.DebugResponse
totalBytesString := units.BytesSize(float64(totalBytes))
// we are forced to check if the whole file needs to be elaborated
// - matchers-condition option set to AND
hasAndCondition := request.CompiledOperators.GetMatchersCondition() == matchers.ANDCondition
// - any matcher has AND condition
for _, matcher := range request.CompiledOperators.Matchers {
if hasAndCondition {
break
}
if matcher.GetCondition() == matchers.ANDCondition {
hasAndCondition = true
}
}
scanner := bufio.NewScanner(reader)
buffer := []byte{}
if request.CompiledOperators.GetMatchersCondition() == matchers.ANDCondition {
if hasAndCondition {
scanner.Buffer(buffer, int(defaultMaxReadSize))
scanner.Split(func(data []byte, atEOF bool) (advance int, token []byte, err error) {
defaultMaxReadSizeInt := int(defaultMaxReadSize)