Fritzdect: fix double-quoting of ain
Some checks failed
Release / call-build-workflow (push) Has been cancelled
Release / Publish Docker :release (push) Has been cancelled
Release / Github & APT (push) Has been cancelled
Release / Demo (push) Has been cancelled
Release / Hassio Addon (push) Has been cancelled

This commit is contained in:
andig 2023-02-24 17:43:13 +01:00
parent fad0288ff7
commit 560ba89734
4 changed files with 8 additions and 10 deletions

View file

@ -26,5 +26,5 @@ render: |
uri: {{ .uri }}
user: {{ .user }}
password: {{ .password }}
ain: "{{ .ain }}" # switch actor identification number without blanks (see AIN number on switch sticker)
ain: {{ .ain }} # switch actor identification number without blanks (see AIN number on switch sticker)
standbypower: {{ .standbypower }}

View file

@ -26,4 +26,4 @@ render: |
uri: {{ .uri }}
user: {{ .user }}
password: {{ .password }}
ain: "{{ .ain }}" # switch actor identification number without blanks (see AIN number on switch sticker)
ain: {{ .ain }} # switch actor identification number without blanks (see AIN number on switch sticker)

View file

@ -12,6 +12,7 @@ func quote(value string) string {
return fmt.Sprintf("'%s'", quoted)
}
// yamlQuote quotes strings for yaml if they would otherwise by modified by the unmarshaler
func yamlQuote(value string) string {
input := fmt.Sprintf("key: %s", value)

View file

@ -4,11 +4,12 @@ import (
"fmt"
"testing"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
)
func TestYamlDecode(t *testing.T) {
for _, value := range []string{`value`, `!value`, `@value`, `"value"`, `"va"lue"`, `va'lue`, `@va'lue`, `0815`, `4711`, `#pwd`, ``} {
for _, value := range []string{`value`, `!value`, `@value`, `"value"`, `"va"lue"`, `va'lue`, `@va'lue`, `0815`, `"0815"`, `4711`, `#pwd`, ``} {
t.Run(value, func(t *testing.T) {
quoted := yamlQuote(value)
input := fmt.Sprintf("key: %s", quoted)
@ -17,13 +18,9 @@ func TestYamlDecode(t *testing.T) {
Value string `yaml:"key"`
}
if err := yaml.Unmarshal([]byte(input), &res); err != nil {
t.Fatalf("expected %s (quoted: %s), got error %v", value, quoted, err)
}
if value != res.Value {
t.Fatalf("expected %s (quoted: %s), got %s", value, quoted, res.Value)
}
err := yaml.Unmarshal([]byte(input), &res)
assert.NoError(t, err)
assert.Equal(t, value, res.Value)
})
}
}