|
8 | 8 | "bytes"
|
9 | 9 | "fmt"
|
10 | 10 | "io"
|
| 11 | + "reflect" |
11 | 12 | "sort"
|
12 | 13 |
|
13 | 14 | "github.com/golang/dep/gps"
|
@@ -54,24 +55,26 @@ func validateManifest(s string) ([]error, error) {
|
54 | 55 | for prop, val := range manifest {
|
55 | 56 | switch prop {
|
56 | 57 | case "metadata":
|
57 |
| - // Invalid if type assertion fails. Not a TOML array of tables. |
58 |
| - // This check is enough for map validation because any non-key-value |
59 |
| - // pair inside array of tables becomes an invalid TOML and parser |
60 |
| - // would fail. |
61 |
| - if _, ok := val.([]interface{}); !ok { |
62 |
| - errs = append(errs, errors.New("metadata should be a TOML array of tables")) |
| 58 | + // Check if metadata is of Map type |
| 59 | + if reflect.TypeOf(val).Kind() != reflect.Map { |
| 60 | + errs = append(errs, errors.New("metadata should be a TOML table")) |
63 | 61 | }
|
64 | 62 | case "dependencies", "overrides":
|
65 | 63 | // Invalid if type assertion fails. Not a TOML array of tables.
|
66 | 64 | if rawProj, ok := val.([]interface{}); ok {
|
67 | 65 | // Iterate through each array of tables
|
68 | 66 | for _, v := range rawProj {
|
69 | 67 | // Check the individual field's key to be valid
|
70 |
| - for key, _ := range v.(map[string]interface{}) { |
| 68 | + for key, value := range v.(map[string]interface{}) { |
71 | 69 | // Check if the key is valid
|
72 | 70 | switch key {
|
73 | 71 | case "name", "branch", "revision", "version", "source":
|
74 | 72 | // valid key
|
| 73 | + case "metadata": |
| 74 | + // Check if metadata is of Map type |
| 75 | + if reflect.TypeOf(value).Kind() != reflect.Map { |
| 76 | + errs = append(errs, fmt.Errorf("metadata in %q should be a TOML table", prop)) |
| 77 | + } |
75 | 78 | default:
|
76 | 79 | // unknown/invalid key
|
77 | 80 | errs = append(errs, fmt.Errorf("Invalid key %q in %q", key, prop))
|
|
0 commit comments