소스 검색

Fix url skip on gitlab detect buildpack

jnfrati 4 년 전
부모
커밋
fc9087fda7
1개의 변경된 파일17개의 추가작업 그리고 2개의 파일을 삭제
  1. 17 2
      api/server/handlers/project_integration/get_gitlab_repo_buildpack.go

+ 17 - 2
api/server/handlers/project_integration/get_gitlab_repo_buildpack.go

@@ -4,6 +4,8 @@ import (
 	"errors"
 	"fmt"
 	"net/http"
+	"net/url"
+	"strings"
 	"sync"
 
 	"github.com/porter-dev/porter/api/server/handlers"
@@ -115,8 +117,21 @@ func (p *GetGitlabRepoBuildpackHandler) ServeHTTP(w http.ResponseWriter, r *http
 		return
 	}
 
+	dir, err := url.QueryUnescape(request.Dir)
+
+	if err != nil {
+		p.HandleAPIError(w, r, apierrors.NewErrForbidden(fmt.Errorf("malformed query param dir")))
+		return
+	}
+
+	dir = strings.TrimPrefix(dir, "./")
+
+	if len(dir) == 0 {
+		dir = "."
+	}
+
 	tree, resp, err := client.Repositories.ListTree(fmt.Sprintf("%s/%s", owner, name), &gitlab.ListTreeOptions{
-		Path: gitlab.String(request.Dir),
+		Path: gitlab.String(dir),
 		Ref:  gitlab.String(branch),
 	})
 
@@ -145,7 +160,7 @@ func (p *GetGitlabRepoBuildpackHandler) ServeHTTP(w http.ResponseWriter, r *http
 				}
 			}()
 			buildpacks.Runtimes[idx].DetectGitlab(
-				client, tree, owner, name, request.Dir, branch,
+				client, tree, owner, name, dir, branch,
 				builderInfoMap[buildpacks.PaketoBuilder], builderInfoMap[buildpacks.HerokuBuilder],
 			)
 			wg.Done()