tighter constraints on allowed paths.
Change-Id: Ie6b121e4733e45288a36dbc2426f556fd5e2832d
This commit is contained in:
+1
-1
@@ -12,7 +12,7 @@ import (
|
|||||||
// Valid checks that p will not confuse the go tool if added to packages.
|
// Valid checks that p will not confuse the go tool if added to packages.
|
||||||
func Valid(p string, packages []Package) bool {
|
func Valid(p string, packages []Package) bool {
|
||||||
for _, pkg := range packages {
|
for _, pkg := range packages {
|
||||||
if strings.HasPrefix(pkg.path, p) {
|
if strings.HasPrefix(pkg.path, p) || strings.HasPrefix(p, pkg.path) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-7
@@ -53,13 +53,6 @@ func TestValid(t *testing.T) {
|
|||||||
in: "bobo",
|
in: "bobo",
|
||||||
want: true,
|
want: true,
|
||||||
},
|
},
|
||||||
{
|
|
||||||
pkgs: []Package{
|
|
||||||
{path: ""},
|
|
||||||
},
|
|
||||||
in: "bobo",
|
|
||||||
want: true,
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
pkgs: []Package{
|
pkgs: []Package{
|
||||||
{path: "bobo"},
|
{path: "bobo"},
|
||||||
@@ -74,6 +67,35 @@ func TestValid(t *testing.T) {
|
|||||||
in: "a/b/c",
|
in: "a/b/c",
|
||||||
want: false,
|
want: false,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
pkgs: []Package{
|
||||||
|
{path: "a/b/c"},
|
||||||
|
},
|
||||||
|
in: "a/b",
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pkgs: []Package{
|
||||||
|
{path: "name/db"},
|
||||||
|
{path: "name/lib"},
|
||||||
|
},
|
||||||
|
in: "name/foo",
|
||||||
|
want: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pkgs: []Package{
|
||||||
|
{path: "a"},
|
||||||
|
},
|
||||||
|
in: "a/b",
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
pkgs: []Package{
|
||||||
|
{path: "foo"},
|
||||||
|
},
|
||||||
|
in: "foo/bar",
|
||||||
|
want: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
pkgs: []Package{
|
pkgs: []Package{
|
||||||
{path: "foo/bar"},
|
{path: "foo/bar"},
|
||||||
|
|||||||
Reference in New Issue
Block a user