Merge pull request #4885 from annasong20/contain-ldr-path

Contain `RepoSpec` path in repo
This commit is contained in:
Kubernetes Prow Robot
2022-11-29 14:35:08 -08:00
committed by GitHub
4 changed files with 38 additions and 0 deletions

View File

@@ -93,6 +93,11 @@ func NewRepoSpecFromURL(n string) (*RepoSpec, error) {
if host == "" {
return nil, fmt.Errorf("url lacks host: %s", n)
}
cleanedPath := filepath.Clean(strings.TrimPrefix(path, string(filepath.Separator)))
if pathElements := strings.Split(cleanedPath, string(filepath.Separator)); len(pathElements) > 0 &&
pathElements[0] == filesys.ParentDir {
return nil, fmt.Errorf("url path exits repo: %s", n)
}
return &RepoSpec{
raw: n, Host: host, OrgRepo: orgRepo,
Dir: notCloned, Path: path, Ref: gitRef, GitSuffix: suffix,

View File

@@ -101,6 +101,10 @@ func TestNewRepoSpecFromUrlErrors(t *testing.T) {
"https://host?ref=group/version/minor_version",
"url lacks orgRepo",
},
"path_exits_repo": {
"https://github.com/org/repo.git//path/../../exits/repo",
"url path exits repo",
},
}
for name, testCase := range badData {