Skip to content

Commit 5118c3b

Browse files
author
Avish Porwal
committed
Fix issue-743 by sanitizing the URL
1 parent 52e3744 commit 5118c3b

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

cmd/publisher/commands/init.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"strings"
1212
"time"
1313

14+
publisherutils "github.com/modelcontextprotocol/registry/cmd/publisher/utils"
1415
apiv0 "github.com/modelcontextprotocol/registry/pkg/api/v0"
1516
"github.com/modelcontextprotocol/registry/pkg/model"
1617
)
@@ -390,7 +391,7 @@ func createServerJSON(
390391
var repo *model.Repository
391392
if repoURL != "" && repoSource != "" {
392393
repo = &model.Repository{
393-
URL: repoURL,
394+
URL: publisherutils.SanitizeRepoURL(repoURL, packageType),
394395
Source: repoSource,
395396
}
396397

cmd/publisher/publisher.exe

24.7 MB
Binary file not shown.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package publisherutils
2+
3+
import (
4+
"strings"
5+
6+
"github.com/modelcontextprotocol/registry/pkg/model"
7+
)
8+
9+
// SanitizeRepoURL normalizes repository URLs based on source/package type.
10+
// - For git sources, it strips the optional "git+" prefix (e.g., "git+https://..." -> "https://...")
11+
// - For other types, returns the URL unchanged unless specific normalization is required
12+
func SanitizeRepoURL(url string, packageType string) string {
13+
switch packageType {
14+
// Some package ecosystems (like npm) may embed git repo URLs; be defensive and strip git+ if present
15+
case model.RegistryTypeNPM:
16+
return strings.TrimPrefix(url, "git+")
17+
default:
18+
return url
19+
}
20+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package publisherutils_test
2+
3+
import (
4+
"testing"
5+
6+
publisherutils "github.com/modelcontextprotocol/registry/cmd/publisher/utils"
7+
"github.com/modelcontextprotocol/registry/pkg/model"
8+
)
9+
10+
func TestSanitizeRepoURL(t *testing.T) {
11+
tests := []struct {
12+
name string
13+
inURL string
14+
pkgType string
15+
wantURL string
16+
}{
17+
{
18+
name: "git url without prefix stays same",
19+
inURL: "https://github.com/jonathanhefner/my-package.git",
20+
pkgType: model.RegistryTypePyPI,
21+
wantURL: "https://github.com/jonathanhefner/my-package.git",
22+
},
23+
{
24+
name: "npm repo url with git+ prefix sanitized",
25+
inURL: "git+https://github.com/org/repo.git",
26+
pkgType: model.RegistryTypeNPM,
27+
wantURL: "https://github.com/org/repo.git",
28+
},
29+
{
30+
name: "npm repo url without prefix unchanged",
31+
inURL: "https://github.com/org/repo.git",
32+
pkgType: model.RegistryTypeNPM,
33+
wantURL: "https://github.com/org/repo.git",
34+
},
35+
}
36+
37+
for _, tt := range tests {
38+
t.Run(tt.name, func(t *testing.T) {
39+
got := publisherutils.SanitizeRepoURL(tt.inURL, tt.pkgType)
40+
if got != tt.wantURL {
41+
t.Fatalf("SanitizeRepoURL(%q,%q)=%q; want %q", tt.inURL, tt.pkgType, got, tt.wantURL)
42+
}
43+
})
44+
}
45+
}

0 commit comments

Comments
 (0)