yaml-cpp icon indicating copy to clipboard operation
yaml-cpp copied to clipboard

Parsing Binary value in Literal syntax resulting in extra newline character being added.

Open davidzchen opened this issue 1 year ago • 2 comments

The following should have the same value:

binary: !!binary AAAAA
binary: !!binary |
  AAAAA

However, when parsed, the latter value has a '\n' appended to the end of it:

#include <cassert>
#include <cstdlib>
#include <string>

#include "yaml-cpp/yaml.h"

int main(int argc, char** argv) {
  YAML::Node n0 = YAML::Load(R"(
    binary: !!binary AAAAA
  )");
  assert(n0["binary"].as<std::string>() == "AAAAA");

  YAML::Node n1 = YAML::Load(R"(
    binary: !!binary |
      AAAAA
  )");
  assert(n1["binary"].as<std::string>() == "AAAAA\n");

  return EXIT_SUCCESS;
}

@jbeder Is this a bug?

davidzchen avatar Jun 28 '24 10:06 davidzchen

Not sure. Can you take a look at the Literal spec? It's possible it adds a new line in that example.

jbeder avatar Jun 28 '24 12:06 jbeder

Here is the section of the spec regarding Literal Style: https://yaml.org/spec/1.2.2/#812-literal-style

I am not familiar with the syntax and format of the spec, but it does mention "final line breaks and trailing empty lines are chomped."

davidzchen avatar Jun 29 '24 08:06 davidzchen