ingydotnet / yaml-libyaml-pm

Perl Binding to libyaml
http://search.cpan.org/dist/YAML-LibYAML/
33 stars 37 forks source link

Don't emit long non-complex hash keys in "complex" notation #90

Open eserte opened 5 years ago

eserte commented 5 years ago

It seems that libyaml uses the ? ... : ... notation for long hash keys (with "long" being more than 128 characters). I think that this notation brings no readability advantage over the "normal" hash notation (in fact, this notation is quite surprising for most humans), and would vote to do a change here (this would probably be a return 1 in the YAML_SCALAR_EVENT case in yaml_emitter_check_simple_key.

After the change the following test script should pass:

#!/usr/bin/perl

use strict;
use warnings;
use YAML::XS qw(Dump);
use Test::More 'no_plan';

my $bla = '123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEFx';
is Dump({ $bla => 1 }), <<'EOF';
---
123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEFx: 1
EOF

__END__
perlpunk commented 5 years ago

This issue should probably be opened in https://github.com/yaml/libyaml instead, as the code you mention is in emitter.c of libyaml, and YAML::XS should usually not modify libyaml sources.