mirror of
https://github.com/jbeder/yaml-cpp.git
synced 2025-09-09 12:41:17 +00:00
Fix formatting when writing \ as a character.
This commit is contained in:
@@ -380,6 +380,8 @@ bool WriteChar(ostream_wrapper& out, char ch) {
|
|||||||
out << "\"\\n\"";
|
out << "\"\\n\"";
|
||||||
} else if (ch == '\b') {
|
} else if (ch == '\b') {
|
||||||
out << "\"\\b\"";
|
out << "\"\\b\"";
|
||||||
|
} else if (ch == '\\') {
|
||||||
|
out << "\"\\\\\"";
|
||||||
} else if ((0x20 <= ch && ch <= 0x7e) || ch == ' ') {
|
} else if ((0x20 <= ch && ch <= 0x7e) || ch == ' ') {
|
||||||
out << "\"" << ch << "\"";
|
out << "\"" << ch << "\"";
|
||||||
} else {
|
} else {
|
||||||
|
@@ -970,6 +970,14 @@ TEST_F(EmitterTest, ValueOfDoubleQuote) {
|
|||||||
ExpectEmit("foo: \"\\\"\"");
|
ExpectEmit("foo: \"\\\"\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(EmitterTest, ValueOfBackslash) {
|
||||||
|
out << YAML::BeginMap;
|
||||||
|
out << YAML::Key << "foo" << YAML::Value << '\\';
|
||||||
|
out << YAML::EndMap;
|
||||||
|
|
||||||
|
ExpectEmit("foo: \"\\\\\"");
|
||||||
|
}
|
||||||
|
|
||||||
class EmitterErrorTest : public ::testing::Test {
|
class EmitterErrorTest : public ::testing::Test {
|
||||||
protected:
|
protected:
|
||||||
void ExpectEmitError(const std::string& expectedError) {
|
void ExpectEmitError(const std::string& expectedError) {
|
||||||
|
Reference in New Issue
Block a user