From d648254c7dc275186615182711be6c46ee267722 Mon Sep 17 00:00:00 2001 From: Alec Thomas Date: Sat, 22 Sep 2018 21:18:22 +1000 Subject: [PATCH] Don't blindly SetString. --- mapper.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mapper.go b/mapper.go index 96e0185..322ab46 100644 --- a/mapper.go +++ b/mapper.go @@ -368,6 +368,9 @@ func pathMapper(r *Registry) MapperFunc { if target.Kind() == reflect.Slice { return sliceDecoder(r)(ctx, target) } + if target.Kind() != reflect.String { + return fmt.Errorf("\"path\" type must be applied to a string not %s", target.Type()) + } path := ctx.Scan.PopValue("file") path = expandPath(path) target.SetString(path) @@ -380,6 +383,9 @@ func existingFileMapper(r *Registry) MapperFunc { if target.Kind() == reflect.Slice { return sliceDecoder(r)(ctx, target) } + if target.Kind() != reflect.String { + return fmt.Errorf("\"existingfile\" type must be applied to a string not %s", target.Type()) + } path := ctx.Scan.PopValue("file") path = expandPath(path) stat, err := os.Stat(path) @@ -399,6 +405,9 @@ func existingDirMapper(r *Registry) MapperFunc { if target.Kind() == reflect.Slice { return sliceDecoder(r)(ctx, target) } + if target.Kind() != reflect.String { + return fmt.Errorf("\"existingdir\" must be applied to a string not %s", target.Type()) + } path := ctx.Scan.PopValue("file") path = expandPath(path) stat, err := os.Stat(path)