diff --git a/server/http_config_helper.go b/server/http_config_helper.go index 06cd9797b..846a17da9 100644 --- a/server/http_config_helper.go +++ b/server/http_config_helper.go @@ -466,9 +466,9 @@ func decodeDeviceConfig(r io.Reader) (configReq, error) { return configReq{}, errors.New("invalid config: cannot mix yaml and other") } - // validate yaml syntax + // validate yaml syntax; tolerate whitespace/comment-only input var tmp map[string]any - if err := yaml.Unmarshal([]byte(res.Yaml), &tmp); err != nil && err != io.EOF { + if err := yaml.Unmarshal([]byte(res.Yaml), &tmp); err != nil && !strings.Contains(err.Error(), "no documents in stream") { return configReq{}, err } diff --git a/util/error_test.go b/util/error_test.go index b62222d83..f8c0b9ac4 100644 --- a/util/error_test.go +++ b/util/error_test.go @@ -13,6 +13,21 @@ func TestYamlFloat(t *testing.T) { require.NoError(t, yaml.Unmarshal([]byte(b), &res)) } +func TestYamlEmpty(t *testing.T) { + var res map[string]any + err := yaml.Unmarshal([]byte(""), &res) + require.ErrorContains(t, err, "no documents in stream") +} + +func TestYamlCommentsOnly(t *testing.T) { + b := `# just a comment +# another comment +` + var res map[string]any + err := yaml.Unmarshal([]byte(b), &res) + require.ErrorContains(t, err, "no documents in stream") +} + func TestYamlError(t *testing.T) { b := `block: data: foo