diff --git a/lib/errorlogger.cpp b/lib/errorlogger.cpp index 183d130025a..7a34e6685c0 100644 --- a/lib/errorlogger.cpp +++ b/lib/errorlogger.cpp @@ -776,6 +776,9 @@ std::string ErrorLogger::toxml(const std::string &str) case '\0': xml += "\\0"; break; + case '\n': + xml += " "; + break; default: if (c >= ' ' && c <= 0x7f) xml += c; diff --git a/test/testcppcheck.cpp b/test/testcppcheck.cpp index 37eebcc8a84..8c53bf2facc 100644 --- a/test/testcppcheck.cpp +++ b/test/testcppcheck.cpp @@ -485,6 +485,22 @@ class TestCppcheck : public TestFixture { " \n" " \n"; ASSERT_EQUALS(expected, cppcheck.getDumpFileContentsRawTokens(files, tokens1)); + + const char code[] = "//x \\ \n" + "y\n" + ";\n"; + + std::istringstream fin(code); + simplecpp::OutputList outputList; + const simplecpp::TokenList tokens2(fin, files, "", &outputList); + const std::string expected2 = " \n" + " \n" + " \n" + " \n" + " \n" + " \n"; + ASSERT_EQUALS(expected2, cppcheck.getDumpFileContentsRawTokens(files, tokens2)); + } void getDumpFileContentsLibrary() const {