Empty strings are silently replaced with 'null' now

Open
#1,290 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

  • #1460 by @mvanhorn — closed without merging

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
38/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Quiet
Tech stack
cpp
Domain
backend

Research direction

Start by reading the yaml-cpp 0.8.0 parsing and scalar conversion behavior for empty YAML values; the issue does not name source files or tests. Reproduce the message: example and compare Scalar() and as<std::string>() for an empty value and an explicit null. Done means the empty value yields an empty string while explicit null remains distinguishable; the issue has a prior unmerged pull request, so check its discussion for context.

Written by the indexing model from the issue text.

Description

bug enhancement help wanted

I've been upgrading from an older yaml-cpp version to 0.8.0.
What I found different is that for empty strings, behavior has changed, they are now replaced with "null".

For example, given the following YAML:

message:
node["message"].as<std::string>()  //=> "null"

I know that such a value can be interpreted as null, hence IsNull() -> true is expected.

However, my parsing for this particular option does not allow for nulls, I always interpret this as a string. In my case message="" vs message="null" makes a difference, and I can't easily distinguish between them.

Can yaml-cpp revert to the old behavior in this case?
For an empty value, I want Scalar() == as<std::string>() == ""
For null value, I want Scalar() == as<std::string>() == "null"

Dominant language
C++
Stars
6.1k
Forks
2.2k
Avg merge
22h 2m
Merged PRs (30d)
1

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from jbeder/yaml-cpp

All issues in jbeder/yaml-cpp

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.