From 84e526d235b281d7077ac70b8202738a5a37233d Mon Sep 17 00:00:00 2001 From: swasti16 Date: Thu, 21 Aug 2025 16:36:03 +0530 Subject: [PATCH] Fix newline in comments rawtokens --- lib/errorlogger.cpp | 3 +++ test/testcppcheck.cpp | 16 ++++++++++++++++ 2 files changed, 19 insertions(+) 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 {