Skip to content

Commit ae2fdad

Browse files
committed
Drop unused newline-escaping helpers
`EncodeNewLines` and `DecodeNewLines` escaped or unescaped `\n` for every string value in a metadata map, and were applied to the flattened metadata before it was handed to the INI/dotenv writers. After the move to a single `SerializeMetadata` pipeline they are no longer called: each store handles newline escaping at the file boundary itself. Signed-off-by: Hidde Beydals <hidde@hhh.computer>
1 parent cc4f025 commit ae2fdad

2 files changed

Lines changed: 0 additions & 52 deletions

File tree

stores/stores.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -606,22 +606,3 @@ func ValToString(v interface{}) string {
606606
}
607607
}
608608

609-
// DecodeNewLines replaces \\n with \n for all string values in the map.
610-
// Used by config stores that do not handle multi-line values (ini, dotenv).
611-
func DecodeNewLines(m map[string]interface{}) {
612-
for k, v := range m {
613-
if s, ok := v.(string); ok {
614-
m[k] = strings.Replace(s, "\\n", "\n", -1)
615-
}
616-
}
617-
}
618-
619-
// EncodeNewLines replaces \n with \\n for all string values in the map.
620-
// Used by config stores that do not handle multi-line values (ini, dotenv).
621-
func EncodeNewLines(m map[string]interface{}) {
622-
for k, v := range m {
623-
if s, ok := v.(string); ok {
624-
m[k] = strings.Replace(s, "\n", "\\n", -1)
625-
}
626-
}
627-
}

stores/stores_test.go

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,36 +26,3 @@ func TestValToString(t *testing.T) {
2626
assert.Equal(t, "a string", ValToString("a string"))
2727
}
2828

29-
func TestDecodeNewLines(t *testing.T) {
30-
tests := []struct {
31-
input map[string]interface{}
32-
want map[string]interface{}
33-
}{
34-
{map[string]interface{}{"mac": "line1\\nline2"}, map[string]interface{}{"mac": "line1\nline2"}},
35-
{map[string]interface{}{"mac": "line1\\n\\n\\nline2\\n\\nline3"}, map[string]interface{}{"mac": "line1\n\n\nline2\n\nline3"}},
36-
}
37-
38-
for _, tt := range tests {
39-
DecodeNewLines(tt.input)
40-
for k, v := range tt.want {
41-
assert.Equal(t, v, tt.input[k])
42-
}
43-
}
44-
}
45-
46-
func TestEncodeNewLines(t *testing.T) {
47-
tests := []struct {
48-
input map[string]interface{}
49-
want map[string]interface{}
50-
}{
51-
{map[string]interface{}{"mac": "line1\nline2"}, map[string]interface{}{"mac": "line1\\nline2"}},
52-
{map[string]interface{}{"mac": "line1\n\n\nline2\n\nline3"}, map[string]interface{}{"mac": "line1\\n\\n\\nline2\\n\\nline3"}},
53-
}
54-
55-
for _, tt := range tests {
56-
EncodeNewLines(tt.input)
57-
for k, v := range tt.want {
58-
assert.Equal(t, v, tt.input[k])
59-
}
60-
}
61-
}

0 commit comments

Comments
 (0)