Skip to content

Commit 1760607

Browse files
committed
csgrep -U: quote embedded NULs in the context
... as they cause problems to some JSON parsers
1 parent 126caad commit 1760607

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

abstract-filter.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <sstream>
2727
#include <vector>
2828

29+
#include <boost/algorithm/string/replace.hpp>
2930
#include <boost/foreach.hpp>
3031

3132
// /////////////////////////////////////////////////////////////////////////////
@@ -136,6 +137,11 @@ void appendCtxLines(
136137
// skip lines before the context lines
137138
continue;
138139

140+
// quote embedded NULs as they cause problems to some JSON parsers
141+
std::string nul;
142+
nul.push_back('\0');
143+
boost::algorithm::replace_all(text, nul, "[NUL]");
144+
139145
// format a single line of the comment
140146
std::ostringstream str;
141147
str << std::fixed << std::setw(5) << line;

0 commit comments

Comments
 (0)