fix(downloadclient): qBittorrent url parse err handling (#1832)

* fix(downloadclient): qBittorrent url parse err handling

* fix(downloadclient): qBittorrent url parse err handling test
This commit is contained in:
ze0s 2024-11-24 00:53:59 +01:00 committed by GitHub
parent a18284ecc6
commit f54c51fa06
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 22 additions and 8 deletions

View file

@ -158,17 +158,20 @@ func (c DownloadClient) Validate() error {
return nil
}
func (c DownloadClient) BuildLegacyHost() string {
func (c DownloadClient) BuildLegacyHost() (string, error) {
if c.Type == DownloadClientTypeQbittorrent {
return c.qbitBuildLegacyHost()
}
return ""
return c.Host, nil
}
// qbitBuildLegacyHost exists to support older configs
func (c DownloadClient) qbitBuildLegacyHost() string {
func (c DownloadClient) qbitBuildLegacyHost() (string, error) {
// parse url
u, _ := url.Parse(c.Host)
u, err := url.Parse(c.Host)
if err != nil {
return "", err
}
// reset Opaque
u.Opaque = ""
@ -200,5 +203,5 @@ func (c DownloadClient) qbitBuildLegacyHost() string {
}
// make into new string and return
return u.String()
return u.String(), nil
}

View file

@ -153,7 +153,8 @@ func TestDownloadClient_qbitBuildLegacyHost(t *testing.T) {
Password: tt.fields.Password,
Settings: tt.fields.Settings,
}
assert.Equalf(t, tt.want, c.qbitBuildLegacyHost(), "qbitBuildLegacyHost()")
got, _ := c.qbitBuildLegacyHost()
assert.Equalf(t, tt.want, got, "qbitBuildLegacyHost()")
})
}
}