Skip to content

Commit 250e301

Browse files
committedFeb 20, 2024
parser-json: remove trailing new-lines from messages
They cannot be propagated through the plain-text format and could cause artificial differences when compared with JSON. Related: https://issues.redhat.com/browse/OSH-552
1 parent 7849312 commit 250e301

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
 

‎src/lib/parser-json.cc

+15
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,20 @@
2626
#include "parser-json-simple.hh"
2727
#include "parser-json-zap.hh"
2828

29+
#include <boost/algorithm/string/trim.hpp>
2930
#include <boost/property_tree/json_parser.hpp>
3031

32+
void removeTrailingNewLines(Defect *pDef)
33+
{
34+
const auto isNewLine = [](const char c){ return c == '\n'; };
35+
36+
// go through all events and remove trailing new-lines from messages
37+
// because they cannot be propagated through the plain-text format
38+
// (and could cause artificial differences when compared with JSON)
39+
for (DefEvent &evt : pDef->events)
40+
boost::trim_right_if(evt.msg, isNewLine);
41+
}
42+
3143
struct JsonParser::Private {
3244
using TDecoderPtr = std::unique_ptr<AbstractTreeDecoder>;
3345

@@ -136,6 +148,9 @@ bool JsonParser::getNext(Defect *def)
136148
if (ok)
137149
d->defNumber++;
138150

151+
// remove trailing new-lines from messages
152+
removeTrailingNewLines(def);
153+
139154
return ok;
140155
}
141156
catch (pt::ptree_error &e) {

0 commit comments

Comments
 (0)