Skip to content

Commit c8a3bed

Browse files
committed
Move major version suffix regex into one place
1 parent cb2ccef commit c8a3bed

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

go/ql/lib/semmle/go/Packages.qll

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class Package extends @package {
2323
* removed.
2424
*/
2525
string getPathWithoutMajorVersionSuffix() {
26-
result = this.getPath().regexpReplaceAll("[./]v\\d+", "")
26+
result = this.getPath().regexpReplaceAll(majorVersionSuffixRegex(), "")
2727
}
2828

2929
/** Gets the scope of this package. */
@@ -33,6 +33,8 @@ class Package extends @package {
3333
string toString() { result = "package " + this.getPath() }
3434
}
3535

36+
string majorVersionSuffixRegex() { result = "[./]v\\d+" }
37+
3638
/**
3739
* Gets an import path that identifies a package in module `mod` with the given path,
3840
* possibly modulo [semantic import versioning](https://github.com/golang/go/wiki/Modules#semantic-import-versioning).

go/ql/lib/semmle/go/dataflow/ExternalFlow.qll

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -322,16 +322,15 @@ private predicate elementSpec(
322322
*/
323323
bindingset[p]
324324
private string interpretPackage(string p) {
325-
exists(Package pkg, string thisVersion, string specifiedVersionRegex |
325+
exists(Package pkg, string thisVersion |
326326
result = pkg.getPath() and
327-
thisVersion = "$THISVERSION" and
328-
specifiedVersionRegex = "[./]v\\d+"
327+
thisVersion = "$THISVERSION"
329328
|
330329
p = result + thisVersion
331330
or
332331
not p = any(string s) + thisVersion and
333332
(
334-
if exists(p.regexpFind(specifiedVersionRegex, 0, _))
333+
if exists(p.regexpFind(majorVersionSuffixRegex(), 0, _))
335334
then result = p
336335
else p = pkg.getPathWithoutMajorVersionSuffix()
337336
)

0 commit comments

Comments
 (0)