go-toml icon indicating copy to clipboard operation
go-toml copied to clipboard

Why does that return empty bytes?

Open gabyx opened this issue 6 months ago • 1 comments

Describe the bug A experienced empty bytes on a custom UnmarshalText type.

To Reproduce

package main

import (
	"fmt"

	"github.com/pelletier/go-toml/v2"
)

type C struct{}

func (c *C) UnmarshalText(bytes []byte) error {
	fmt.Printf("Bytes: %v", bytes)
	if len(bytes) == 0 {
		panic("why is this empty??")
	}
	return nil
}

type Steps struct {
	Config C
}

type Config struct {
	Steps Steps
}

func main() {
	file := `
[steps]
config = { a = "asfd" }
`
	c := Config{}
	err := toml.Unmarshal([]byte(file), &c)
	if err != nil {
		panic(err)
	}
}

Expected behavior

I expected the function UnmarshalText to not receive empty bytes.

Versions

  • go-toml: 2.2.2
  • go: 1.22.3
  • operating system: Linux

gabyx avatar Aug 07 '24 16:08 gabyx