Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Trim ending "/" when saving the VCS instanceURL

天舟3ad3efef8bf2
diff --git a/backend/server/vcs.go b/backend/server/vcs.go
index bc82696a0b..a7be86df3e 100644
--- a/backend/server/vcs.go
+++ b/backend/server/vcs.go
@@ -22,6 +22,8 @@ func (s *Server) registerVCSRoutes(g *echo.Group) {
if err := jsonapi.UnmarshalPayload(c.Request().Body, vcsCreate); err != nil {
return echo.NewHTTPError(http.StatusBadRequest, "Malformatted create VCS request").SetInternal(err)
}
+ // Trim ending "/"
+ vcsCreate.InstanceURL = strings.TrimRight(vcsCreate.InstanceURL, "/")
vcsCreate.ApiURL = fmt.Sprintf("%s/%s", vcsCreate.InstanceURL, gitlab.ApiPath)
vcs, err := s.VCSService.CreateVCS(context.Background(), vcsCreate)
diff --git a/backend/store/migration/0001_init_schema.up.sql b/backend/store/migration/0001_init_schema.up.sql
index dab3ade87e..32c5675a65 100644
--- a/backend/store/migration/0001_init_schema.up.sql
+++ b/backend/store/migration/0001_init_schema.up.sql
@@ -648,12 +648,18 @@ CREATE TABLE vcs (
name TEXT NOT NULL,
`type` TEXT NOT NULL CHECK (`type` IN ('GITLAB_SELF_HOST')),
instance_url TEXT NOT NULL CHECK (
- instance_url LIKE 'http:/%'
- OR instance_url LIKE 'https:/%'
+ (
+ instance_url LIKE 'http:/%'
+ OR instance_url LIKE 'https:/%'
+ )
+ AND instance_url = rtrim(instance_url, '/')
),
api_url TEXT NOT NULL CHECK (
- api_url LIKE 'http:/%'
- OR api_url LIKE 'https:/%'
+ (
+ api_url LIKE 'http:/%'
+ OR api_url LIKE 'https:/%'
+ )
+ AND api_url = rtrim(api_url, '/')
),
application_id TEXT NOT NULL,
secret TEXT NOT NULL,