@@ -5,6 +5,7 @@ overlay[local?]
55module ;
66
77import semmle.go.dependencies.Dependencies
8+ private import codeql.util.SemVer
89
910/**
1011 * A SemVer-formatted version string in a dependency.
@@ -17,63 +18,42 @@ class DependencySemVer extends string {
1718
1819 DependencySemVer ( ) {
1920 this = dep .getDepVersion ( ) and
20- normalized = normalizeSemver ( this )
21+ normalized = normalizeSemVer ( this )
2122 }
2223
2324 /**
2425 * Holds if this version may be before `last`.
2526 */
2627 bindingset [ last]
27- predicate maybeBefore ( string last ) { normalized < normalizeSemver ( last ) }
28+ predicate maybeBefore ( string last ) { normalized < normalizeSemVer ( last ) }
2829
2930 /**
3031 * Holds if this version may be after `first`.
3132 */
3233 bindingset [ first]
33- predicate maybeAfter ( string first ) { normalizeSemver ( first ) < normalized }
34+ predicate maybeAfter ( string first ) { normalizeSemVer ( first ) < normalized }
3435
3536 /**
3637 * Holds if this version may be between `first` (inclusive) and `last` (exclusive).
3738 */
3839 bindingset [ first, last]
3940 predicate maybeBetween ( string first , string last ) {
40- normalizeSemver ( first ) <= normalized and
41- normalized < normalizeSemver ( last )
41+ normalizeSemVer ( first ) <= normalized and
42+ normalized < normalizeSemVer ( last )
4243 }
4344
4445 /**
4546 * Holds if this version is equivalent to `other`.
4647 */
4748 bindingset [ other]
48- predicate is ( string other ) { normalized = normalizeSemver ( other ) }
49+ predicate is ( string other ) { normalized = normalizeSemVer ( other ) }
4950
5051 /**
5152 * Gets the dependency that uses this string.
5253 */
5354 Dependency getDependency ( ) { result = dep }
5455}
5556
56- bindingset [ str]
57- private string leftPad ( string str ) { result = ( "000" + str ) .suffix ( str .length ( ) ) }
58-
59- /**
60- * Normalizes a SemVer string such that the lexicographical ordering
61- * of two normalized strings is consistent with the SemVer ordering.
62- *
63- * Pre-release information and build metadata is not yet supported.
64- */
65- bindingset [ orig]
66- private string normalizeSemver ( string orig ) {
67- exists ( string pattern , string major , string minor , string patch |
68- pattern = "v?(\\d+)\\.(\\d+)\\.(\\d+)(\\D.*)?" and
69- major = orig .regexpCapture ( pattern , 1 ) and
70- minor = orig .regexpCapture ( pattern , 2 ) and
71- patch = orig .regexpCapture ( pattern , 3 )
72- |
73- result = leftPad ( major ) + "." + leftPad ( minor ) + "." + leftPad ( patch )
74- )
75- }
76-
7757/**
7858 * A version string in a dependency that has a SemVer, but also contains a git commit SHA.
7959 *
0 commit comments