Skip to content

Commit 2f04f1f

Browse files
fix: KVTJ having a equal in value (#21)
1 parent d883673 commit 2f04f1f

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

cmd/keyValueToJson.go

+19-1
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,34 @@ var keyValueToJson = &cobra.Command{
3939
continue
4040
}
4141

42+
// Skip comments
4243
if strings.HasPrefix(e, "#") || strings.HasPrefix(e, "//") {
4344
continue
4445
}
4546

47+
// Skip lines without "="
4648
if !strings.Contains(e, "=") {
4749
continue
4850
}
4951

52+
// Split the line by "="
5053
parts := strings.Split(e, "=")
51-
m[strings.TrimSpace(parts[0])] = strings.TrimSpace(parts[1])
54+
55+
var value string
56+
57+
// If the value contains "=" then join the parts otherwise take the second part
58+
if len(parts) > 2 {
59+
value = strings.Join(parts[1:], "=")
60+
} else {
61+
value = parts[1]
62+
}
63+
64+
// Remove " and ' from the value string
65+
value = strings.Trim(value, "\"")
66+
value = strings.Trim(value, "'")
67+
68+
// Add the key-value pair to the map
69+
m[strings.TrimSpace(parts[0])] = strings.TrimSpace(value)
5270
}
5371
jsonString, _ := json.MarshalIndent(m, "", " ")
5472

0 commit comments

Comments
 (0)