From 440427c44df657515be863b4c2d00422f56838fa Mon Sep 17 00:00:00 2001 From: Matt Farina Date: Wed, 18 Nov 2020 12:22:36 -0500 Subject: [PATCH] Forcing ordered operation when generating regex Range was used to iterate over the operations as part of generating the regex. Range iterations are random. There were cases where the empty key caused the regex to be generated as invalid. This change removes the range so that the order is always the same. Closes #155 --- constraints.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/constraints.go b/constraints.go index 7420823..547613f 100644 --- a/constraints.go +++ b/constraints.go @@ -164,14 +164,11 @@ func init() { "^": constraintCaret, } - ops := make([]string, 0, len(constraintOps)) - for k := range constraintOps { - ops = append(ops, regexp.QuoteMeta(k)) - } + ops := `=||!=|>|<|>=|=>|<=|=<|~|~>|\^` constraintRegex = regexp.MustCompile(fmt.Sprintf( `^\s*(%s)\s*(%s)\s*$`, - strings.Join(ops, "|"), + ops, cvRegex)) constraintRangeRegex = regexp.MustCompile(fmt.Sprintf( @@ -180,12 +177,12 @@ func init() { findConstraintRegex = regexp.MustCompile(fmt.Sprintf( `(%s)\s*(%s)`, - strings.Join(ops, "|"), + ops, cvRegex)) validConstraintRegex = regexp.MustCompile(fmt.Sprintf( `^(\s*(%s)\s*(%s)\s*\,?)+$`, - strings.Join(ops, "|"), + ops, cvRegex)) }