Skip to content

Commit 2c5535b

Browse files
authored
Merge pull request #199 from mattfarina/bug-197
Fix issue with - ranges being transformed to something imparsible
2 parents 249ee2d + b1bb761 commit 2c5535b

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

constraints.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ func rewriteRange(i string) string {
586586
}
587587
o := i
588588
for _, v := range m {
589-
t := fmt.Sprintf(">= %s, <= %s", v[1], v[11])
589+
t := fmt.Sprintf(">= %s, <= %s ", v[1], v[11])
590590
o = strings.Replace(o, v[0], t, 1)
591591
}
592592

constraints_test.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,8 @@ func TestNewConstraint(t *testing.T) {
243243
{"12.3.34.1234", 0, 0, true},
244244
{"12.3.34 ~1.2.3", 1, 2, false},
245245
{"12.3.34~ 1.2.3", 0, 0, true},
246+
247+
{"1.0.0 - 2.0.0, <=2.0.0", 1, 3, false},
246248
}
247249

248250
for _, tc := range tests {
@@ -394,6 +396,10 @@ func TestConstraintsCheck(t *testing.T) {
394396
{"~1.2.3", "1.3.2", false},
395397
{"~1.1", "1.2.3", false},
396398
{"~1.3", "2.4.5", false},
399+
400+
// Ranges should work in conjunction with other constraints anded together.
401+
{"1.0.0 - 2.0.0 <=2.0.0", "1.5.0", true},
402+
{"1.0.0 - 2.0.0, <=2.0.0", "1.5.0", true},
397403
}
398404

399405
for _, tc := range tests {
@@ -421,16 +427,18 @@ func TestRewriteRange(t *testing.T) {
421427
c string
422428
nc string
423429
}{
424-
{"2 - 3", ">= 2, <= 3"},
425-
{"2 - 3, 2 - 3", ">= 2, <= 3,>= 2, <= 3"},
426-
{"2 - 3, 4.0.0 - 5.1", ">= 2, <= 3,>= 4.0.0, <= 5.1"},
430+
{"2 - 3", ">= 2, <= 3 "},
431+
{"2 - 3, 2 - 3", ">= 2, <= 3 ,>= 2, <= 3 "},
432+
{"2 - 3, 4.0.0 - 5.1", ">= 2, <= 3 ,>= 4.0.0, <= 5.1 "},
433+
{"2 - 3 4.0.0 - 5.1", ">= 2, <= 3 >= 4.0.0, <= 5.1 "},
434+
{"1.0.0 - 2.0.0 <=2.0.0", ">= 1.0.0, <= 2.0.0 <=2.0.0"},
427435
}
428436

429437
for _, tc := range tests {
430438
o := rewriteRange(tc.c)
431439

432440
if o != tc.nc {
433-
t.Errorf("Range %s rewritten incorrectly as '%s'", tc.c, o)
441+
t.Errorf("Range %s rewritten incorrectly as %q instead of expected %q", tc.c, o, tc.nc)
434442
}
435443
}
436444
}

0 commit comments

Comments
 (0)