Skip to content

Commit f03447f

Browse files
committed
cstrans-df-run: escape also \n in JSON output
1 parent cbec9a8 commit f03447f

File tree

4 files changed

+35
-1
lines changed

4 files changed

+35
-1
lines changed

cstrans-df-run.cc

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ void appendExecArgs(TStringList *pExecList, const std::string &str)
8383

8484
case ES_BACK_SLASH:
8585
// one back-slash has been consumed
86-
arg.push_back(c);
86+
if ('n' == c)
87+
arg.push_back('\n');
88+
else if ('t' == c)
89+
arg.push_back('\t');
90+
else
91+
// FIXME: this works for back-slash and quote only
92+
arg.push_back(c);
8793
state = ES_SEEK_QUOT_CLOSE;
8894
continue;
8995

@@ -130,6 +136,7 @@ std::string runQuoteArg(std::string arg)
130136
{
131137
boost::algorithm::replace_all(arg, "\\", "\\\\");
132138
boost::algorithm::replace_all(arg, "\"", "\\\"");
139+
boost::algorithm::replace_all(arg, "\n", "\\n");
133140
boost::algorithm::replace_all(arg, "\t", "\\t");
134141
return arg;
135142
}

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,3 +211,4 @@ tests_cstrans_df_run(0004)
211211
tests_cstrans_df_run(0005)
212212
tests_cstrans_df_run(0006)
213213
tests_cstrans_df_run(0007)
214+
tests_cstrans_df_run(0008)

tests/cstrans-df-run/0008-stdin.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM openshift/golang-builder:1.11 AS builder
2+
ENV SOURCE_GIT_COMMIT=39c2c111ea818cd16dbd11e31cc682cf2b4042d3 SOURCE_GIT_TAG=golang-github-prometheus-alertmanager-4.0.0-0.100.0-115-g39c2c11
3+
COPY . ${ALERTMANAGER_GOPATH}
4+
RUN ["sh", "-c", "echo \tOK\n"]
5+
FROM ubi7:7.6-159
6+
ENV SOURCE_GIT_COMMIT=39c2c111ea818cd16dbd11e31cc682cf2b4042d3 SOURCE_GIT_TAG=golang-github-prometheus-alertmanager-4.0.0-0.100.0-115-g39c2c11
7+
8+
CMD [ "--storage.path=/alertmanager" ]
9+
10+
LABEL \
11+
io.k8s.description="This is the Prometheus Alert Manager image." \
12+
com.redhat.component="golang-github-prometheus-alertmanager-container" \
13+
maintainer="OpenShift Development <[email protected]>"

tests/cstrans-df-run/0008-stdout.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM openshift/golang-builder:1.11 AS builder
2+
ENV SOURCE_GIT_COMMIT=39c2c111ea818cd16dbd11e31cc682cf2b4042d3 SOURCE_GIT_TAG=golang-github-prometheus-alertmanager-4.0.0-0.100.0-115-g39c2c11
3+
COPY . ${ALERTMANAGER_GOPATH}
4+
RUN ["/opt/cov-sa-2019.09/bin/cov-build", "--dir=/cov", "--append-log", "sh", "-c", "echo \tOK\n"]
5+
FROM ubi7:7.6-159
6+
ENV SOURCE_GIT_COMMIT=39c2c111ea818cd16dbd11e31cc682cf2b4042d3 SOURCE_GIT_TAG=golang-github-prometheus-alertmanager-4.0.0-0.100.0-115-g39c2c11
7+
8+
CMD [ "--storage.path=/alertmanager" ]
9+
10+
LABEL \
11+
io.k8s.description="This is the Prometheus Alert Manager image." \
12+
com.redhat.component="golang-github-prometheus-alertmanager-container" \
13+
maintainer="OpenShift Development <[email protected]>"

0 commit comments

Comments
 (0)