main: keep .conf transport URLs when per-type flags are unset

buildTransportSpecs overrode every [Transport] URL with its per-type flag
(--vyandex-url, --yandex-url, ...) even when the flag was unset, so an
exit started from --config ran vyandex with an empty URL
(Get "": unsupported protocol scheme "") and never reached its document.
Only a flag that was set overrides now.
This commit is contained in:
meepo161
2026-09-26 19:08:10 +03:00
committed by p1neappleXpress
parent e6af2b4403
commit d7dc7b8335
2 changed files with 24 additions and 1 deletions
+3 -1
View File
@@ -50,7 +50,9 @@ func parseTransportList(s string) ([]transportSpec, error) {
// per-type URL flags (--yandex-url, --mailru-url, ...) and global settings.
func buildTransportSpecs(specs []transportSpec, urls map[string]string, extra map[string]map[string]interface{}) []transportSpec {
for i := range specs {
if u, ok := urls[specs[i].Type]; ok {
// Only a flag that was set overrides: the unset ones are "" and
// would wipe the URL of a .conf [Transport] section.
if u, ok := urls[specs[i].Type]; ok && u != "" {
specs[i].URL = u
}
if p, ok := extra[specs[i].Type]; ok {
+21
View File
@@ -0,0 +1,21 @@
package main
import "testing"
// A per-type URL flag overrides a .conf transport's URL only when it is set:
// the unset flags are "", and overriding with them wiped the document URL of
// every [Transport] section, so a --config exit started vyandex with no URL.
func TestBuildTransportSpecsKeepsConfURL(t *testing.T) {
specs := []transportSpec{
{Name: "vyandex", Type: "vyandex", URL: "https://docs.yandex.ru/edit/d/conf"},
{Name: "yandex", Type: "yandex", URL: "https://disk.yandex.ru/i/conf"},
}
urls := map[string]string{"vyandex": "", "yandex": "https://disk.yandex.ru/i/flag"}
got := buildTransportSpecs(specs, urls, nil)
if got[0].URL != "https://docs.yandex.ru/edit/d/conf" {
t.Fatalf("unset flag wiped the conf URL: %q", got[0].URL)
}
if got[1].URL != "https://disk.yandex.ru/i/flag" {
t.Fatalf("a set flag must override the conf URL: %q", got[1].URL)
}
}