Skip to content

yaml.Unmarshal of empty document nils out the map provided #805

@bep

Description

@bep
github.com/goccy/go-yaml@v1.18.0 
package main

import (
	"log"

	"github.com/goccy/go-yaml"
)

func main() {
	data := []byte(`
# empty document
`)

	target := make(map[string]any)

	err := yaml.Unmarshal(data, &target)
	if err != nil {
		log.Fatalf("error: %v", err)
	}

	if target == nil {
		log.Println("target is nil")
	}
}

I would expect yaml.Unmarshal to preserve the empty (non-nil) map in the above example.

gohugoio/hugo#14074

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions