Skip to content

Commit fadcdcb

Browse files
committed
Improved escaping
1 parent e1357b5 commit fadcdcb

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

keyvalue_test.go

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package keyvalues
22

33
import (
4-
"log"
54
"testing"
65
)
76

@@ -217,7 +216,6 @@ func TestKeyValue_MergeInto(t *testing.T) {
217216
if err != nil {
218217
t.Error(err)
219218
}
220-
log.Println(result.Children())
221219

222220
actual,err := result.Find("bar")
223221
if actual == nil {

reader.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ func readScope(reader *bufio.Reader, scope *KeyValue) *KeyValue {
9191
if len(prop) == 1 {
9292
//Create new scope
9393
kv := &KeyValue{
94-
key: strings.Trim(prop[0], tokenEscape),
94+
key: trim(prop[0]),
9595
valueType: ValueArray,
9696
parent: scope,
9797
}
@@ -113,15 +113,19 @@ func readScope(reader *bufio.Reader, scope *KeyValue) *KeyValue {
113113
func parseKV(line string) *KeyValue {
114114
prop := strings.Split(line, tokenSeparator)
115115
// value also defined on this line
116-
val := strings.Trim(strings.Replace(line, prop[0]+tokenSeparator, "", -1), tokenEscape)
116+
val := trim(strings.Replace(line, prop[0], "", -1))
117117

118118
return &KeyValue{
119-
key: strings.Trim(prop[0], tokenEscape),
119+
key: trim(prop[0]),
120120
valueType: getType(val),
121121
value: append(make([]interface{}, 0), val),
122122
}
123123
}
124124

125125
func isCharacterEscaped(value string, char string) bool {
126126
return strings.LastIndex(value, tokenEscape) >= strings.LastIndex(value, char)
127+
}
128+
129+
func trim(value string) string {
130+
return strings.Trim(strings.TrimSpace(value), tokenEscape)
127131
}

0 commit comments

Comments
 (0)