Skip to content

Commit

Permalink
Improved escaping
Browse files Browse the repository at this point in the history
  • Loading branch information
Galaco committed Dec 24, 2018
1 parent e1357b5 commit fadcdcb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 0 additions & 2 deletions keyvalue_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package keyvalues

import (
"log"
"testing"
)

Expand Down Expand Up @@ -217,7 +216,6 @@ func TestKeyValue_MergeInto(t *testing.T) {
if err != nil {
t.Error(err)
}
log.Println(result.Children())

actual,err := result.Find("bar")
if actual == nil {
Expand Down
10 changes: 7 additions & 3 deletions reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func readScope(reader *bufio.Reader, scope *KeyValue) *KeyValue {
if len(prop) == 1 {
//Create new scope
kv := &KeyValue{
key: strings.Trim(prop[0], tokenEscape),
key: trim(prop[0]),
valueType: ValueArray,
parent: scope,
}
Expand All @@ -113,15 +113,19 @@ func readScope(reader *bufio.Reader, scope *KeyValue) *KeyValue {
func parseKV(line string) *KeyValue {
prop := strings.Split(line, tokenSeparator)
// value also defined on this line
val := strings.Trim(strings.Replace(line, prop[0]+tokenSeparator, "", -1), tokenEscape)
val := trim(strings.Replace(line, prop[0], "", -1))

return &KeyValue{
key: strings.Trim(prop[0], tokenEscape),
key: trim(prop[0]),
valueType: getType(val),
value: append(make([]interface{}, 0), val),
}
}

func isCharacterEscaped(value string, char string) bool {
return strings.LastIndex(value, tokenEscape) >= strings.LastIndex(value, char)
}

func trim(value string) string {
return strings.Trim(strings.TrimSpace(value), tokenEscape)
}

0 comments on commit fadcdcb

Please sign in to comment.