Skip to content

The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu

fix(share): strip private suffixes from root remote URLs (#986)

Divyam Talwardd3c0e581538
diff --git a/pkg/asymptoteobserve/share.go b/pkg/asymptoteobserve/share.go
index 2c111780..44e68bba 100644
--- a/pkg/asymptoteobserve/share.go
+++ b/pkg/asymptoteobserve/share.go
@@ -788,6 +788,9 @@ func ShareRemoteURL(raw string) string {
return ""
}
rest := raw[scheme+3:]
+ if cut := strings.IndexAny(rest, "?#"); cut >= 0 {
+ rest = rest[:cut]
+ }
host, path := rest, ""
if slash := strings.Index(rest, "/"); slash >= 0 {
host, path = rest[:slash], rest[slash:]
@@ -798,9 +801,6 @@ func ShareRemoteURL(raw string) string {
if host == "" {
return ""
}
- if cut := strings.IndexAny(path, "?#"); cut >= 0 {
- path = path[:cut]
- }
return raw[:scheme+3] + host + path
}
// scp-style [user@]host:path. The colon must come before any slash, and a one-letter host is a
diff --git a/pkg/asymptoteobserve/share_test.go b/pkg/asymptoteobserve/share_test.go
index 0c7aea3d..36fac5a0 100644
--- a/pkg/asymptoteobserve/share_test.go
+++ b/pkg/asymptoteobserve/share_test.go
@@ -411,18 +411,21 @@ func TestShareBundleSummary(t *testing.T) {
func TestShareRemoteURL(t *testing.T) {
cases := map[string]string{
- "https://user:[email protected]/acme/repo.git": "https://github.com/acme/repo.git",
- "[email protected]:acme/repo.git": "github.com:acme/repo.git",
- "ssh://git@host:22/acme/repo": "ssh://host:22/acme/repo",
- "https://github.com/acme/repo?token=abc": "https://github.com/acme/repo",
- "": "",
- "github.com:acme/repo.git": "github.com:acme/repo.git",
- "/home/alice/src/foo": "",
- "../foo.git": "",
- "~/src/foo": "",
- "file:///Users/alice/repos/foo": "",
- `C:\Users\alice\repo`: "",
- "./a:b": "",
+ "https://user:[email protected]/acme/repo.git": "https://github.com/acme/repo.git",
+ "[email protected]:acme/repo.git": "github.com:acme/repo.git",
+ "ssh://git@host:22/acme/repo": "ssh://host:22/acme/repo",
+ "https://github.com/acme/repo?token=abc": "https://github.com/acme/repo",
+ "https://user:[email protected]?token=abc": "https://git.example.test",
+ "https://git.example.test#frag": "https://git.example.test",
+ "https://git.example.test?redirect=/[email protected]": "https://git.example.test",
+ "": "",
+ "github.com:acme/repo.git": "github.com:acme/repo.git",
+ "/home/alice/src/foo": "",
+ "../foo.git": "",
+ "~/src/foo": "",
+ "file:///Users/alice/repos/foo": "",
+ `C:\Users\alice\repo`: "",
+ "./a:b": "",
}
for in, want := range cases {
if got := ShareRemoteURL(in); got != want {