Skip to content

Commit 3967c33

Browse files
authored
Fix newline in comments rawtokens (#7763)
1 parent 8a2af82 commit 3967c33

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

lib/errorlogger.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -776,6 +776,9 @@ std::string ErrorLogger::toxml(const std::string &str)
776776
case '\0':
777777
xml += "\\0";
778778
break;
779+
case '\n':
780+
xml += "
";
781+
break;
779782
default:
780783
if (c >= ' ' && c <= 0x7f)
781784
xml += c;

test/testcppcheck.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,22 @@ class TestCppcheck : public TestFixture {
485485
" <file index=\"0\" name=\"test.cpp\"/>\n"
486486
" </rawtokens>\n";
487487
ASSERT_EQUALS(expected, cppcheck.getDumpFileContentsRawTokens(files, tokens1));
488+
489+
const char code[] = "//x \\ \n"
490+
"y\n"
491+
";\n";
492+
493+
std::istringstream fin(code);
494+
simplecpp::OutputList outputList;
495+
const simplecpp::TokenList tokens2(fin, files, "", &outputList);
496+
const std::string expected2 = " <rawtokens>\n"
497+
" <file index=\"0\" name=\"test.cpp\"/>\n"
498+
" <file index=\"1\" name=\"\"/>\n"
499+
" <tok fileIndex=\"1\" linenr=\"1\" column=\"1\" str=\"//x &#10;y\"/>\n"
500+
" <tok fileIndex=\"1\" linenr=\"3\" column=\"1\" str=\";\"/>\n"
501+
" </rawtokens>\n";
502+
ASSERT_EQUALS(expected2, cppcheck.getDumpFileContentsRawTokens(files, tokens2));
503+
488504
}
489505

490506
void getDumpFileContentsLibrary() const {

0 commit comments

Comments
 (0)