Skip to content

Commit

Permalink
Fix formatting when writing \ as a character.
Browse files Browse the repository at this point in the history
  • Loading branch information
jbeder committed Oct 12, 2016
1 parent 85af926 commit 086fec5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/emitterutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ bool WriteChar(ostream_wrapper& out, char ch) {
out << "\"\\n\"";
} else if (ch == '\b') {
out << "\"\\b\"";
} else if (ch == '\\') {
out << "\"\\\\\"";
} else if ((0x20 <= ch && ch <= 0x7e) || ch == ' ') {
out << "\"" << ch << "\"";
} else {
Expand Down
8 changes: 8 additions & 0 deletions test/integration/emitter_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -970,6 +970,14 @@ TEST_F(EmitterTest, ValueOfDoubleQuote) {
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 {
protected:
void ExpectEmitError(const std::string& expectedError) {
Expand Down

0 comments on commit 086fec5

Please sign in to comment.