commit ca155cdcf527862e602e3a4c54b5c11bf766538c
parent 45432eef4ece0be89f08f182cddb95a1f1479d33
Author: cfillion <cfillion@users.noreply.github.com>
Date: Sun, 10 Jul 2016 22:30:36 -0400
don't crash when encountering empty lines in changelogs
Diffstat:
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/src/ostream.cpp b/src/ostream.cpp
@@ -34,8 +34,14 @@ void OutputStream::indented(const string &text)
istringstream stream(text);
string line;
- while(getline(stream, line, '\n'))
- m_stream << "\x20\x20" << line.substr(line.find_first_not_of('\x20')) << "\r\n";
+ while(getline(stream, line, '\n')) {
+ const auto first = line.find_first_not_of('\x20');
+
+ if(first != string::npos)
+ m_stream << "\x20\x20" << line.substr(first);
+
+ m_stream << "\r\n";
+ }
}
OutputStream &OutputStream::operator<<(const Version &ver)
diff --git a/test/ostream.cpp b/test/ostream.cpp
@@ -50,4 +50,10 @@ TEST_CASE("output version", M) {
stream << ver;
REQUIRE(stream.str() == "v1.2.3\r\n + added super cool feature\r\n + fixed all the bugs!\r\n");
}
+
+ SECTION("changelog with empty lines") {
+ ver.setChangelog("line1\n\nline2");
+ stream << ver; // no crash!
+ REQUIRE(stream.str() == "v1.2.3\r\n line1\r\n\r\n line2\r\n");
+ }
}