Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions svn.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,11 +378,14 @@ func detectRemoteFromInfoCommand(infoOut string) (string, error) {
if urlIndex == -1 {
return "", fmt.Errorf("Remote not specified in svn info")
}
urlEndIndex := strings.Index(string(sBytes[urlIndex:]), "\n")
urlEndIndex := strings.Index(string(sBytes[urlIndex:]), "\r\n")
if urlEndIndex == -1 {
urlEndIndex = strings.Index(string(sBytes[urlIndex:]), "\r")
urlEndIndex = strings.Index(string(sBytes[urlIndex:]), "\n")
if urlEndIndex == -1 {
return "", fmt.Errorf("unable to parse remote URL for svn info")
urlEndIndex = strings.Index(string(sBytes[urlIndex:]), "\r")
if urlEndIndex == -1 {
return "", fmt.Errorf("unable to parse remote URL for svn info")
}
}
}

Expand Down
55 changes: 55 additions & 0 deletions svn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,58 @@ func TestSvnInit(t *testing.T) {
t.Errorf("Svn Init returns wrong version: %s", v)
}
}

func TestDetectRemoteFromInfoCommand(t *testing.T) {
tests := []struct {
name string
input string
expected string
hasError bool
}{
{
name: "Unix line ending (LF)",
input: "Path: /svn/repo\nURL: https://example.com/repo\nRepository Root: https://example.com\n",
expected: "https://example.com/repo",
hasError: false,
},
{
name: "Windows line ending (CRLF)",
input: "Path: /svn/repo\r\nURL: https://example.com/repo\r\nRepository Root: https://example.com\r\n",
expected: "https://example.com/repo",
hasError: false,
},
{
name: "Old Mac line ending (CR)",
input: "Path: /svn/repo\rURL: https://example.com/repo\rRepository Root: https://example.com\r",
expected: "https://example.com/repo",
hasError: false,
},
{
name: "URL not found",
input: "Path: /svn/repo\nRepository Root: https://example.com\n",
expected: "",
hasError: true,
},
{
name: "URL with no line ending",
input: "Path: /svn/repo\nURL: https://example.com/repo",
expected: "",
hasError: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
result, err := detectRemoteFromInfoCommand(tt.input)
if tt.hasError && err == nil {
t.Errorf("expected error but got none")
}
if !tt.hasError && err != nil {
t.Errorf("unexpected error: %v", err)
}
if result != tt.expected {
t.Errorf("expected %q, got %q", tt.expected, result)
}
})
}
}
Loading