Skip to content

Commit cb2ccef

Browse files
committed
Refactor suffix check
1 parent c045e77 commit cb2ccef

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

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

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -322,17 +322,18 @@ private predicate elementSpec(
322322
*/
323323
bindingset[p]
324324
private string interpretPackage(string p) {
325-
exists(Package pkg | result = pkg.getPath() |
326-
exists(string thisVersion, string specifiedVersionRegex |
327-
thisVersion = "$THISVERSION" and
328-
specifiedVersionRegex = "[./]v\\d+"
329-
|
330-
if p.suffix(p.length() - thisVersion.length()) = thisVersion
331-
then result = p.prefix(p.length() - 12)
332-
else
333-
if exists(p.regexpFind(specifiedVersionRegex, 0, _))
334-
then result = p
335-
else p = pkg.getPathWithoutMajorVersionSuffix()
325+
exists(Package pkg, string thisVersion, string specifiedVersionRegex |
326+
result = pkg.getPath() and
327+
thisVersion = "$THISVERSION" and
328+
specifiedVersionRegex = "[./]v\\d+"
329+
|
330+
p = result + thisVersion
331+
or
332+
not p = any(string s) + thisVersion and
333+
(
334+
if exists(p.regexpFind(specifiedVersionRegex, 0, _))
335+
then result = p
336+
else p = pkg.getPathWithoutMajorVersionSuffix()
336337
)
337338
)
338339
or

0 commit comments

Comments
 (0)