mirror of
https://github.com/github/codeql.git
synced 2026-01-29 14:23:03 +01:00
Restrict 'package' to real package paths
This commit is contained in:
@@ -32,9 +32,10 @@ class Package extends @package {
|
||||
* For example, `package("github.com/go-pg/pg", "types")` gets an import path that can
|
||||
* refer to `"github.com/go-pg/pg/types"`, but also to `"github.com/go-pg/pg/v10/types"`.
|
||||
*/
|
||||
bindingset[result, mod, path]
|
||||
bindingset[mod, path]
|
||||
string package(string mod, string path) {
|
||||
// "\Q" and "\E" start and end a quoted section of a regular expression. Anything like "." or "*" that
|
||||
// "*" that comes between them is not interpreted as it would normally be in a regular expression.
|
||||
result.regexpMatch("\\Q" + mod + "\\E([/.]v[^/]+)?($|/)\\Q" + path + "\\E")
|
||||
result.regexpMatch("\\Q" + mod + "\\E([/.]v[^/]+)?($|/)\\Q" + path + "\\E") and
|
||||
result = any(Package p).getPath()
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/nonexistent-test-pkg"
|
||||
"github.com/nonexistent/test"
|
||||
test2 "github.com/nonexistent/v2/test"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
||||
@@ -3,16 +3,16 @@ import go
|
||||
from string path
|
||||
where
|
||||
(
|
||||
path = "PackageName/v2/test" or // OK
|
||||
path = "PackageName/test" or // OK
|
||||
path = "PackageName//v//test" or // NOT OK
|
||||
path = "PackageName//v/test" or // NOT OK
|
||||
path = "PackageName/v//test" or // NOT OK
|
||||
path = "PackageName/v/asd/v2/test" or // NOT OK
|
||||
path = "PackageName/v/test" or // NOT OK
|
||||
path = "PackageName//v2//test" or // NOT OK
|
||||
path = "PackageName//v2/test" or // NOT OK
|
||||
path = "PackageName/v2//test" // NOT OK
|
||||
path = "github.com/nonexistent/v2/test" or // OK
|
||||
path = "github.com/nonexistent/test" or // OK
|
||||
path = "github.com/nonexistent//v//test" or // NOT OK
|
||||
path = "github.com/nonexistent//v/test" or // NOT OK
|
||||
path = "github.com/nonexistent/v//test" or // NOT OK
|
||||
path = "github.com/nonexistent/v/asd/v2/test" or // NOT OK
|
||||
path = "github.com/nonexistent/v/test" or // NOT OK
|
||||
path = "github.com/nonexistent//v2//test" or // NOT OK
|
||||
path = "github.com/nonexistent//v2/test" or // NOT OK
|
||||
path = "github.com/nonexistent/v2//test" // NOT OK
|
||||
) and
|
||||
path = package("PackageName", "test")
|
||||
path = package("github.com/nonexistent", "test")
|
||||
select path
|
||||
|
||||
1
ql/test/library-tests/semmle/go/Packages/vendor/github.com/nonexistent/test/stub.go
generated
vendored
Normal file
1
ql/test/library-tests/semmle/go/Packages/vendor/github.com/nonexistent/test/stub.go
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
package test
|
||||
1
ql/test/library-tests/semmle/go/Packages/vendor/github.com/nonexistent/v2/test/stub.go
generated
vendored
Normal file
1
ql/test/library-tests/semmle/go/Packages/vendor/github.com/nonexistent/v2/test/stub.go
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
package test
|
||||
Reference in New Issue
Block a user