diff --git a/doc/100_references.rst b/doc/100_references.rst index dc2b40ee7..44dcc6673 100644 --- a/doc/100_references.rst +++ b/doc/100_references.rst @@ -681,7 +681,7 @@ return JSON. Any different value for this header means API version 1. The placeholder ``{path}`` in this document is a path to the repository, so that multiple different repositories can be accessed. The default path is -``/``. +``/``. The path must end with a slash. POST {path}?create=true ======================= diff --git a/internal/backend/rest/config.go b/internal/backend/rest/config.go index 34d7958fb..60c6bf92b 100644 --- a/internal/backend/rest/config.go +++ b/internal/backend/rest/config.go @@ -32,6 +32,10 @@ func ParseConfig(s string) (interface{}, error) { } s = s[5:] + if !strings.HasSuffix(s, "/") { + s += "/" + } + u, err := url.Parse(s) if err != nil { diff --git a/internal/backend/rest/config_test.go b/internal/backend/rest/config_test.go index ed5413323..2d8e32a73 100644 --- a/internal/backend/rest/config_test.go +++ b/internal/backend/rest/config_test.go @@ -19,24 +19,34 @@ var configTests = []struct { s string cfg Config }{ - {"rest:http://localhost:1234", Config{ - URL: parseURL("http://localhost:1234"), - Connections: 5, - }}, + { + s: "rest:http://localhost:1234", + cfg: Config{ + URL: parseURL("http://localhost:1234/"), + Connections: 5, + }, + }, + { + s: "rest:http://localhost:1234/", + cfg: Config{ + URL: parseURL("http://localhost:1234/"), + Connections: 5, + }, + }, } func TestParseConfig(t *testing.T) { - for i, test := range configTests { - cfg, err := ParseConfig(test.s) - if err != nil { - t.Errorf("test %d:%s failed: %v", i, test.s, err) - continue - } + for _, test := range configTests { + t.Run("", func(t *testing.T) { + cfg, err := ParseConfig(test.s) + if err != nil { + t.Fatalf("%s failed: %v", test.s, err) + } - if !reflect.DeepEqual(cfg, test.cfg) { - t.Errorf("test %d:\ninput:\n %s\n wrong config, want:\n %v\ngot:\n %v", - i, test.s, test.cfg, cfg) - continue - } + if !reflect.DeepEqual(cfg, test.cfg) { + t.Fatalf("\ninput: %s\n wrong config, want:\n %v\ngot:\n %v", + test.s, test.cfg, cfg) + } + }) } }