From f587a5f4f0f37f0b3a911dba7560cd0f5a6ff6cc Mon Sep 17 00:00:00 2001 From: Alexander Neumann Date: Sat, 25 Mar 2017 15:39:38 +0100 Subject: [PATCH] options: fail when key is configured twice --- src/restic/options/options.go | 5 +++++ src/restic/options/options_test.go | 12 ++++++++++++ 2 files changed, 17 insertions(+) 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) {