Skip to content

Empty line at start of string causes parse failure #65

@evanphx

Description

@evanphx

Hi all, big fan. Been chasing a bug for a while and finally found it today. Here is the repro:

func TestEmptyLine(t *testing) {
	iso := map[string]any{
		"attrs": []any{
			map[string]any{
				"value": "\ndebug",
			},
		},
	}

	var node yaml.Node
	err = node.Encode(iso)
	require.NoError(t, err, "Failed to parse YAML attributes")
}

Encode returns an error saying: "yaml: line 1: did not find expected key". Encode does a yaml generation step, then sends that yaml back through the parser to update Node. I got in the middle there and say this as the generated yaml:

attrs:
    - value: |4-
        debug

I found that if the string does not contain a newline at the start, the encoding works fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions