go-yaml / yaml

YAML support for the Go language.
Other
6.84k stars 1.04k forks source link

Encoder never ends on data with cycles #927

Open fgm opened 1 year ago

fgm commented 1 year ago

Data with cycles cause the encoder to never return.

Example: https://go.dev/play/p/sWfo5Hj4M6V

The encoder could at least detect the cycle and return an error like the json package does, or even in some cases use a reference to represent the cycle pointer.

dolmen commented 1 year ago

@fgm Note that yaml.v3 doesn't preserve references when deserializing. Example.

Edit: I'm wrong. references are preserved when deserializing into yaml.Node. Example.