YAML Emitter using YAML::DoubleQuoted when emitted in a destructor of a staticly created struct/class
@alex-thiessen-for-siemens is already working on this.
Since Sep 20, 2026.
- #1500 by @alex-thiessen-for-siemens — open
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
Research direction
Start with the issue’s example and inspect emitter.h, especially YAML::Emitter::Write(const std::string&) and its StringFormat::value regex check. Reproduce the output difference between the call in main() and the destructor, then trace why the regex match changes during static destruction. Done means both serializations emit the same unquoted YAML; the issue does not name a test file.
Written by the indexing model from the issue text.
Description
What steps will reproduce the problem?
-
Create a struct/class containing a destructor and a function to serialize an arbitrary type of data, with the destructor calling the serialization function.
-
Create a static instance of that class and call the serilization function at least once.
What is the expected output? What do you see instead?
The expected output would be to see the serialized data, as many times as requested, beeing exactly the same, however, the last time the yaml string is printed, all keys, as well as all strings, are wrapped in double quotes.
Example
struct EmitterTest
{
~EmitterTest()
{
Serialize();
}
void Serialize()
{
YAML::Emitter out;
out << YAML::BeginMap << YAML::Key << "Test";
out << YAML::BeginMap;
out << YAML::Key << "String1" << YAML::Value << "String1";
out << YAML::Key << "String2" << YAML::Value << "String2";
out << YAML::Key << "String3" << YAML::Value << "Foo";
out << YAML::EndMap;
out << YAML::EndMap;
std::cout << out.c_str() << std::endl;
}
}
static EmitterTest s_Test;
int main()
{
s_Test.Serialize();
}
Expected output:
Test:
String1: String1
String2: String2
String3: Foo
Test:
String1: String1
String2: String2
String3: Foo
Actual output:
Test:
String1: String1
String2: String2
String3: Foo
"Test":
"String1": "String1"
"String2": "String2"
"String3": "Foo"
yaml-cpp version: 0.8.0
Additional Information
Note that this only happens when Serialize() is called once before destruction. Digging into the problem makes the problem pretty obvious: In emitter.h the function YAML::Emitter::Write(const std::string&) queries the StringFormat::value, by trying to match the string with a regex. This regex match returns false in the serialization called in the destructor, otherwise it returns true.
- Dominant language
- C++
- Stars
- 6.1k
- Forks
- 2.2k
- Avg merge
- 22h 2m
- Merged PRs (30d)
- 1
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from jbeder/yaml-cpp
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
-
Difficulty 3/5 1-2 days Newbie friendliness 62/100
-
Difficulty 3/5 Half a day Newbie friendliness 55/100
-
Difficulty 3/5 1-2 days Newbie friendliness 62/100
Similar issues
-
bug difficulty: easy good first issue help wanted
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
nagisa-kamishiro/rosehip#73 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
pocoproject/poco#5626 ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
md ファイルの段落途中の改行をなくすOpen
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day