Skip to content

Commit 4824f3e

Browse files
committed
new url clone method
1 parent f9b71f4 commit 4824f3e

3 files changed

Lines changed: 12 additions & 14 deletions

File tree

pkg/core/utils.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ func prepareRepoURL(repoURL *url.URL, proxyURL *url.URL) (*url.URL, *http.BasicA
2020
if repoURL == nil {
2121
return nil, nil
2222
}
23-
repo := *repoURL // copy
23+
repo := repoURL.Clone()
2424

2525
// parse auth from url and delete the credentials
26-
auth := authFromURL(&repo)
26+
auth := authFromURL(repo)
2727
repo.User = nil
2828

2929
// add proxy if specified
3030
if proxyURL != nil {
31-
return useCorsProxy(&repo, proxyURL), auth
31+
return useCorsProxy(repo, proxyURL), auth
3232
}
3333

34-
return &repo, auth
34+
return repo, auth
3535
}
3636

3737
func repoURLFromCalendar(cal *Calendar) (*url.URL, error) {
@@ -65,8 +65,7 @@ func useCorsProxy(original, proxy *url.URL) *url.URL {
6565
return original
6666
}
6767
if original == nil {
68-
u := *proxy
69-
return &u
68+
return proxy.Clone()
7069
}
7170

7271
p := *proxy // copy

pkg/core/utils_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,11 @@ func TestUseCorsProxy(t *testing.T) {
6969
proxy *url.URL
7070
want *url.URL
7171
}{
72+
{
73+
name: "no original",
74+
proxy: mustParseURL("http://cors-proxy.abc"),
75+
want: mustParseURL("http://cors-proxy.abc"),
76+
},
7277
{
7378
name: "basic proxy",
7479
original: mustParseURL("https://github.com/joe/my-calendar.git"),

pkg/gitmerge/merge_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package gitmerge
33
import (
44
"encoding/json/v2"
55
"errors"
6-
"io"
76
"testing"
87
"time"
98

@@ -341,14 +340,9 @@ func assertHeadEvent(t *testing.T, repo *gogit.Repository, want *time.Time) {
341340
}
342341
defer r.Close()
343342

344-
data, err := io.ReadAll(r)
345-
if err != nil {
346-
t.Fatalf("read event blob: %v", err)
347-
}
348-
349343
var got testEvent
350-
if err := json.Unmarshal(data, &got); err != nil {
351-
t.Fatalf("unmarshal event: %v", err)
344+
if err := json.UnmarshalRead(r, &got); err != nil {
345+
t.Fatalf("read event blob: %v", err)
352346
}
353347

354348
if !got.UpdatedAt.Equal(*want) {

0 commit comments

Comments
 (0)