GithubHelp home page GithubHelp logo

Comments (4)

perlpunk avatar perlpunk commented on June 14, 2024

This was a deliberate change, however, I also think it's not the best behaviour and I thought already about changing it.
The background is a bit more complicated.
YAML::PP uses the YAML 1.2 JSON Schema as default (instead of the Core Schema).
https://yaml.org/spec/1.2/spec.html#id2803231

The YAML 1.2 JSON Schema, however, is actually a strict schema which does not allow any unquoted scalars expect the special types. (For completeness, I want to implement a JSONStrict Schema at some point).
I am using a modified variant of that schema that detects values like true|false|null|123|3.14 as special types, but everything else as a string, even if unquoted.
The problem with that is, that there is no clear definition about what to do with the empty scalar - should it be the empty string (as per my definition above that everything else is a string) or null. In the strict schema it would be disallowed.

I realized that using null here has advantages in several ways, so I'll change it back.

edit: If you want to be compatible with official YAML 1.2 (other processors supporting 1.2 often only support the Core Schema) then you should enable the Core Schema. But note that this has a lot more special values: https://yaml.org/spec/1.2/spec.html#id2804923
None of the schemas is actually compatible to what YAML::XS is doing, for example.

edit2: The actual change in 0.013 was:

Change default schema from Core to JSON

https://metacpan.org/changes/distribution/YAML-PP

from yaml-pp-p5.

pplu avatar pplu commented on June 14, 2024

I'm OK with changing our application to use the Core schema (my initial test script is already working with the schema change). I wasn't conscious that the schema change had implications in the treatment of null / undef values while I was tracking down the reason for our test failures.

As to what YAML::PP should do by default: you have a better overview of everything. Our use case is covered by configuring the schema, so we're happy with that.

Attached is new test script working with current 0.018

#!/usr/bin/env perl

use strict;
use warnings;

use Test::More;
use YAML::PP;

my $pp = YAML::PP->new(schema => ['Core']);

{
  my $yaml = "key:";

  my $perl = $pp->load_string($yaml);
  ok(exists($perl->{ key }), 'key exists');
  is($perl->{ key }, undef, 'and is an undef');

  like($pp->dump_string($perl), qr/key: null/);

  my $roundtrip = $pp->load_string($pp->dump_string($perl));
  ok(exists($roundtrip->{ key }), 'key exists');
  is($roundtrip->{ key }, undef, 'and is an undef');
}

done_testing;

from yaml-pp-p5.

perlpunk avatar perlpunk commented on June 14, 2024

As to what YAML::PP should do by default: you have a better overview of everything

At some point I would like to create a table that shows an overview of which schema treats which values special, so others will also have a better understanding =)

from yaml-pp-p5.

perlpunk avatar perlpunk commented on June 14, 2024

Finally I got around to creating the table:
https://perlpunk.github.io/YAML-PP-p5/schema-examples.html
And here are the definitions: https://perlpunk.github.io/YAML-PP-p5/schemas.html

I also changed back to Core as default.

from yaml-pp-p5.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.