diff --git a/src/restic/options/options.go b/src/restic/options/options.go index 635216041..0c620c8a3 100644 --- a/src/restic/options/options.go +++ b/src/restic/options/options.go @@ -32,6 +32,11 @@ func Parse(in []string) (Options, error) { if key == "" { return Options{}, errors.Fatalf("empty key is not a valid option") } + + if v, ok := opts[key]; ok && v != value { + return Options{}, errors.Fatalf("key %q present more than once", key) + } + opts[key] = value } diff --git a/src/restic/options/options_test.go b/src/restic/options/options_test.go index feead1c89..2717bc9c3 100644 --- a/src/restic/options/options_test.go +++ b/src/restic/options/options_test.go @@ -33,6 +33,14 @@ var optsTests = []struct { "k2": "more spaces = not evil", }, }, + { + []string{"x=1", "foo=bar", "y=2", "foo=bar"}, + Options{ + "x": "1", + "y": "2", + "foo": "bar", + }, + }, } func TestParseOptions(t *testing.T) { @@ -58,6 +66,10 @@ var invalidOptsTests = []struct { []string{"=bar", "bar=baz", "k="}, "empty key is not a valid option", }, + { + []string{"x=1", "foo=bar", "y=2", "foo=baz"}, + `key "foo" present more than once`, + }, } func TestParseInvalidOptions(t *testing.T) {