Fix parsing of single quoted keys (#201)

Patch #193 doesn't work correctly because that must be handled by the
lexer, and `parseKey()` must not handle escape sequences.

Ref #61
This commit is contained in:
Kazuyoshi Kato
2017-10-26 23:26:39 -07:00
committed by Thomas Pelletier
parent 9bf0212445
commit 4874e8477b
7 changed files with 77 additions and 112 deletions
+3 -6
View File
@@ -71,18 +71,15 @@ func (t *Tree) Keys() []string {
}
// Get the value at key in the Tree.
// Key is a dot-separated path (e.g. a.b.c).
// Key is a dot-separated path (e.g. a.b.c) without single/double quoted strings.
// If you need to retrieve non-bare keys, use GetPath.
// Returns nil if the path does not exist in the tree.
// If keys is of length zero, the current tree is returned.
func (t *Tree) Get(key string) interface{} {
if key == "" {
return t
}
comps, err := parseKey(key)
if err != nil {
return nil
}
return t.GetPath(comps)
return t.GetPath(strings.Split(key, "."))
}
// GetPath returns the element in the tree indicated by 'keys'.