From 57b479f88022ce880e9bfbce35b9f2690a126c3f Mon Sep 17 00:00:00 2001 From: Valentin Rothberg Date: Mon, 19 Mar 2018 16:48:36 +0100 Subject: [PATCH] sysregistries: remove all trailing slashes Remove all (instead of one) trailing slashes from any specified registry string. Signed-off-by: Valentin Rothberg --- pkg/sysregistries/system_registries.go | 4 ++-- pkg/sysregistries/system_registries_test.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pkg/sysregistries/system_registries.go b/pkg/sysregistries/system_registries.go index 6d2f7544d4..c56e32dddc 100644 --- a/pkg/sysregistries/system_registries.go +++ b/pkg/sysregistries/system_registries.go @@ -31,11 +31,11 @@ type tomlConfig struct { } `toml:"registries"` } -// normalizeRegistries removes a trailing slash from registries, which is a +// normalizeRegistries removes trailing slashes from registries, which is a // common pitfall when configuring registries (e.g., "docker.io/library/). func normalizeRegistries(regs *registries) { for i := range regs.Registries { - regs.Registries[i] = strings.TrimSuffix(regs.Registries[i], "/") + regs.Registries[i] = strings.TrimRight(regs.Registries[i], "/") } } diff --git a/pkg/sysregistries/system_registries_test.go b/pkg/sysregistries/system_registries_test.go index b9a1ff8ba5..43821ee847 100644 --- a/pkg/sysregistries/system_registries_test.go +++ b/pkg/sysregistries/system_registries_test.go @@ -39,9 +39,9 @@ func TestGetRegistriesWithBadData(t *testing.T) { } func TestGetRegistriesWithTrailingSlash(t *testing.T) { - answer := []string{"no-slash.com:5000/path", "one-slash.com", "two-slashes.com/"} + answer := []string{"no-slash.com:5000/path", "one-slash.com", "two-slashes.com", "three-slashes.com:5000"} testConfig = []byte(`[registries.search] - registries= ['no-slash.com:5000/path', 'one-slash.com/', 'two-slashes.com//'] + registries= ['no-slash.com:5000/path', 'one-slash.com', 'two-slashes.com//', 'three-slashes.com:5000///'] `) // note: only one trailing gets removed registriesConfig, err := GetRegistries(nil)