From 5de44ba4d6a222a8d4b35234443180ec933b7dd1 Mon Sep 17 00:00:00 2001 From: stephen mcquay Date: Wed, 2 Mar 2016 22:06:17 -0800 Subject: [PATCH] tighter constraints on allowed paths. Change-Id: Ie6b121e4733e45288a36dbc2426f556fd5e2832d --- storage.go | 2 +- vain_test.go | 36 +++++++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/storage.go b/storage.go index 15baf78..aa2840d 100644 --- a/storage.go +++ b/storage.go @@ -12,7 +12,7 @@ import ( // Valid checks that p will not confuse the go tool if added to packages. func Valid(p string, packages []Package) bool { for _, pkg := range packages { - if strings.HasPrefix(pkg.path, p) { + if strings.HasPrefix(pkg.path, p) || strings.HasPrefix(p, pkg.path) { return false } } diff --git a/vain_test.go b/vain_test.go index 202993a..a7a7ed5 100644 --- a/vain_test.go +++ b/vain_test.go @@ -53,13 +53,6 @@ func TestValid(t *testing.T) { in: "bobo", want: true, }, - { - pkgs: []Package{ - {path: ""}, - }, - in: "bobo", - want: true, - }, { pkgs: []Package{ {path: "bobo"}, @@ -74,6 +67,35 @@ func TestValid(t *testing.T) { in: "a/b/c", 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{ {path: "foo/bar"},