Fix #122: Partially invalid JSONPath ending with string does not return an error

This commit is contained in:
TwinProduction
2021-06-05 18:41:42 -04:00
parent ca977fefa8
commit f9d132c369
2 changed files with 143 additions and 172 deletions

View File

@ -25,6 +25,9 @@ func walk(path string, object interface{}) (string, int, error) {
case map[string]interface{}:
return walk(strings.Replace(path, fmt.Sprintf("%s.", currentKey), "", 1), value)
case string:
if len(keys) > 1 {
return "", 0, fmt.Errorf("couldn't walk through '%s', because '%s' was a string instead of an object", keys[1], currentKey)
}
return value, len(value), nil
case []interface{}:
return fmt.Sprintf("%v", value), len(value), nil