Skip to content

Commit 0d57208

Browse files
committed
json-writer: replace replace \u0009 by \t in the output
... to make it parseable by older versions of Boost libraries
1 parent 0b94c6e commit 0d57208

8 files changed

+71
-0
lines changed

json-writer.cc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,11 @@ void JsonWriter::flush() {
109109
boost::iostreams::basic_regex_filter<char> reFilterSlash(reSlash, "\\1\\2");
110110
str.push(reFilterSlash);
111111

112+
// create a regex-based filter to replace \u0009 by \t
113+
const boost::regex reTab("\\\\u0009");
114+
boost::iostreams::basic_regex_filter<char> reFilterTab(reTab, "\\\\t");
115+
str.push(reFilterTab);
116+
112117
str.push(d->str);
113118

114119
// encode scan properties if we have some

tests/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ test_csgrep(csgrep "32-shellcheck-raw" )
142142
test_csgrep(csgrep "33-cov-format-errors" )
143143
test_csgrep(csgrep "34-csgrep-color" )
144144
test_csgrep(csgrep "35-cov-format-errors" )
145+
test_csgrep(csgrep "36-csgrep-json" )
146+
test_csgrep(csgrep "37-csgrep-json" )
145147
test_csparser(csparser-5.8 00)
146148
test_csparser(csparser-5.8 01)
147149
test_csparser(csparser-5.8 02)

tests/csgrep/36-csgrep-json-args.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--mode=json

tests/csgrep/36-csgrep-json-stdin.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Error: SHELLCHECK_WARNING:
2+
/etc/rc.d/rc.sysinit:492:13: warning: Quote this to prevent word splitting. [SC2046]
3+
# 490| if [ -n "$SELINUX_STATE" -a "$READONLY" != "yes" ]; then
4+
# 491| if [ -f /.autorelabel ] || strstr "$cmdline" autorelabel ; then
5+
# 492|-> restorecon $(awk '!/^#/ && $4 !~ /noauto/ && $2 ~ /^\// { print $2 }' /etc/fstab) >/dev/null 2>&1
6+
# 493| fi
7+
# 494| fi
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
{
2+
"defects": [
3+
{
4+
"checker": "SHELLCHECK_WARNING",
5+
"key_event_idx": 0,
6+
"events": [
7+
{
8+
"file_name": "/etc/rc.d/rc.sysinit",
9+
"line": 492,
10+
"column": 13,
11+
"event": "warning",
12+
"message": "Quote this to prevent word splitting. [SC2046]",
13+
"verbosity_level": "0"
14+
},
15+
{
16+
"file_name": "",
17+
"line": 0,
18+
"event": "#",
19+
"message": " 490| if [ -n \"$SELINUX_STATE\" -a \"$READONLY\" != \"yes\" ]; then",
20+
"verbosity_level": "1"
21+
},
22+
{
23+
"file_name": "",
24+
"line": 0,
25+
"event": "#",
26+
"message": " 491| if [ -f /.autorelabel ] || strstr \"$cmdline\" autorelabel ; then",
27+
"verbosity_level": "1"
28+
},
29+
{
30+
"file_name": "",
31+
"line": 0,
32+
"event": "#",
33+
"message": " 492|-> \trestorecon $(awk '!/^#/ && $4 !~ /noauto/ && $2 ~ /^\\// { print $2 }' /etc/fstab) >/dev/null 2>&1",
34+
"verbosity_level": "1"
35+
},
36+
{
37+
"file_name": "",
38+
"line": 0,
39+
"event": "#",
40+
"message": " 493| fi",
41+
"verbosity_level": "1"
42+
},
43+
{
44+
"file_name": "",
45+
"line": 0,
46+
"event": "#",
47+
"message": " 494| fi",
48+
"verbosity_level": "1"
49+
}
50+
]
51+
}
52+
]
53+
}

tests/csgrep/37-csgrep-json-args.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

tests/csgrep/37-csgrep-json-stdin.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
36-csgrep-json-stdout.txt
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
36-csgrep-json-stdin.txt

0 commit comments

Comments
 (0)