Skip to content

Commit 7e314bd

Browse files
committed
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
1 parent 60c7ae8 commit 7e314bd

File tree

2 files changed

+5
-8
lines changed

2 files changed

+5
-8
lines changed

.github/workflows/test.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ jobs:
44
test:
55
strategy:
66
matrix:
7-
go-version: [1.12.x, 1.13.x, 1.14.x]
7+
go-version: [1.12.x, 1.13.x, 1.14.x, 1.15.x]
88
platform: [ubuntu-latest, macos-latest, windows-latest]
99
runs-on: ${{ matrix.platform }}
1010
steps:

constraints.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,14 +164,11 @@ func init() {
164164
"^": constraintCaret,
165165
}
166166

167-
ops := make([]string, 0, len(constraintOps))
168-
for k := range constraintOps {
169-
ops = append(ops, regexp.QuoteMeta(k))
170-
}
167+
ops := `=||!=|>|<|>=|=>|<=|=<|~|~>|\^`
171168

172169
constraintRegex = regexp.MustCompile(fmt.Sprintf(
173170
`^\s*(%s)\s*(%s)\s*$`,
174-
strings.Join(ops, "|"),
171+
ops,
175172
cvRegex))
176173

177174
constraintRangeRegex = regexp.MustCompile(fmt.Sprintf(
@@ -180,12 +177,12 @@ func init() {
180177

181178
findConstraintRegex = regexp.MustCompile(fmt.Sprintf(
182179
`(%s)\s*(%s)`,
183-
strings.Join(ops, "|"),
180+
ops,
184181
cvRegex))
185182

186183
validConstraintRegex = regexp.MustCompile(fmt.Sprintf(
187184
`^(\s*(%s)\s*(%s)\s*\,?)+$`,
188-
strings.Join(ops, "|"),
185+
ops,
189186
cvRegex))
190187
}
191188

0 commit comments

Comments
 (0)