mustangostang / spyc

A simple YAML loader/dumper class for PHP
MIT License
707 stars 207 forks source link

String with trailing newline ends up with extra "|" at the start #41

Closed D91 closed 7 years ago

D91 commented 9 years ago

Test code. Using Spyc 0.5.1

#!/usr/bin/env php
<?php

require_once("lib/Spyc.php");
function test_roundtrip($data){
  $yaml = Spyc::YAMLDump($data);
  $parsed = Spyc::YAMLLoad($yaml);
  if($parsed !== $data){
    echo "STARTED WITH:  " . json_encode($data), "\n";
    echo "ENDED UP WITH: ".json_encode($parsed), "\n";
    echo "YAML:\n$yaml\n";
    echo "\n------------------\n";
  }
}
test_roundtrip(array('a' => "b\n"));

Output:

STARTED WITH:  {"a":"b\n"}
ENDED UP WITH: {"a":"|\n  b"}
YAML:

---
a: |
  |
    b