File tree Expand file tree Collapse file tree 2 files changed +12
-14
lines changed Expand file tree Collapse file tree 2 files changed +12
-14
lines changed Original file line number Diff line number Diff line change @@ -212,25 +212,11 @@ func rpmvercmp(strA, strB string) int {
212
212
} else if len (b ) > len (a ) {
213
213
return - 1
214
214
}
215
-
216
215
} else if unicode .IsNumber ([]rune (b )[0 ]) {
217
216
// a is alpha, b is numeric
218
217
return - 1
219
218
}
220
219
221
- // This is the last iteration.
222
- if i == segs - 1 {
223
- // If there is a tilde in a segment past the min number of segments, find
224
- // it before we rely on string compare.
225
- lia := strings .LastIndex (strA , "~" )
226
- lib := strings .LastIndex (strB , "~" )
227
- if lia > lib {
228
- return - 1
229
- } else if lia < lib {
230
- return 1
231
- }
232
- }
233
-
234
220
// string compare
235
221
if a < b {
236
222
return - 1
@@ -244,6 +230,13 @@ func rpmvercmp(strA, strB string) int {
244
230
return 0
245
231
}
246
232
233
+ // If there is a tilde in a segment past the min number of segments, find it.
234
+ if len (segsa ) > segs && []rune (segsa [segs ])[0 ] == '~' {
235
+ return - 1
236
+ } else if len (segsb ) > segs && []rune (segsb [segs ])[0 ] == '~' {
237
+ return 1
238
+ }
239
+
247
240
// whoever has the most segments wins
248
241
if len (segsa ) > len (segsb ) {
249
242
return 1
Original file line number Diff line number Diff line change @@ -162,6 +162,11 @@ func TestParseAndCompare(t *testing.T) {
162
162
{"1.0~rc1~git123" , EQUAL , "1.0~rc1~git123" },
163
163
{"1.0~rc1~git123" , LESS , "1.0~rc1" },
164
164
{"1.0~rc1" , GREATER , "1.0~rc1~git123" },
165
+ {"1~" , GREATER , "1~~" },
166
+ {"2~" , GREATER , "1" },
167
+ {"1.0" , GREATER , "1.0-~" },
168
+ {"1.0" , LESS , "1.0-1~" },
169
+ {"~" , GREATER , "~~" },
165
170
}
166
171
167
172
var (
You can’t perform that action at this time.
0 commit comments