Skip to content

Loaded self-referential structures have only one reference per referent #77

@Kodiologist

Description

@Kodiologist

This issue ia a copy of https://rt.cpan.org/Public/Bug/Display.html?id=53278, originally reported 1 Jan 2010. The bug still exists as of YAML-LibYAML 0.69.

The problem is best explained with an example. This works as you would expect:

$ perl -e 'use YAML::XS; my $a = [["a"], ["b"]]; push @$a, $a->[0]; $a->[0] = "x"; print Dump($a), "\n";'
---
- x
- - b
- - a

But if you dump and reload $a between the push and the second assignment, you get this:

$ perl -e 'use YAML::XS; my $a = [["a"], ["b"]]; push @$a, $a->[0]; $a = Load Dump $a; $a->[0] = "x"; print Dump($a), "\n";'
---
- x
- - b
- x

Assigning to $a->[0] mysteriously changed $a->[2] as well. Sorta-kinda-workaround: YAML.pm doesn't have this bug. Also, recreating $a after loading it prevents the weirdness:

$ perl -e 'use YAML::XS; my $a = [["a"], ["b"]]; push @$a, $a->[0]; $a = Load Dump $a; $a = [@$a]; $a->[0] = "x"; print Dump($a), "\n";'
---
- x
- - b
- - a

(This is perl 5, version 26, subversion 0 (v5.26.0) built for x86_64-linux-gnu-thread-multi. Output of uname -a: Linux Xorn 4.13.0-21-generic #24-Ubuntu SMP Mon Dec 18 17:29:16 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions