mirror of
https://github.com/rsyslog/rsyslog.git
synced 2026-06-15 11:42:40 +02:00
Merge pull request #7076 from rsyslog/codex/fix-malformed-json-output-in-jsonftree
template: fix jsonftree fallback to valid flat JSON
This commit is contained in:
commit
af3e8bf725
@ -916,7 +916,8 @@ rsRetVal tplToString(struct template *__restrict__ const pTpl,
|
||||
*/
|
||||
pTpe = pTpl->pEntryRoot;
|
||||
iBuf = 0;
|
||||
const int isJsonFlat = (pTpl->optFormatEscape == JSONF && !pTpl->bJsonTreeEnabled);
|
||||
const int isJsonFlat = (pTpl->optFormatEscape == JSONF &&
|
||||
(!pTpl->bJsonTreeEnabled || pTpl->bJsonTreeBuilt == TPL_JSON_TREE_UNSUPPORTED));
|
||||
if (isJsonFlat) {
|
||||
if (iparam->lenBuf < 2) /* we reserve one char for the final \0! */
|
||||
CHKiRet(ExtendBuf(iparam, 2));
|
||||
|
||||
@ -188,7 +188,8 @@ TESTS_DEFAULT = \
|
||||
template-json.sh \
|
||||
template-property-transformations.sh \
|
||||
template-pure-json.sh \
|
||||
template-jsonf-nested.sh \
|
||||
template-jsonf-nested.sh \
|
||||
template-jsonf-nested-fallback-flat.sh \
|
||||
template-jsonf-trailing-backslash.sh \
|
||||
template-missing-jsonvars-queue.sh \
|
||||
template-pos-from-to.sh \
|
||||
|
||||
34
tests/template-jsonf-nested-fallback-flat.sh
Executable file
34
tests/template-jsonf-nested-fallback-flat.sh
Executable file
@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
# Verify jsonftree conflict fallback still emits valid flat JSON (ASL 2.0).
|
||||
. ${srcdir:=.}/diag.sh init
|
||||
|
||||
generate_conf
|
||||
add_conf '
|
||||
template(name="nested_fallback" type="list" option.jsonftree="on") {
|
||||
constant(outname="a" value="A" format="jsonf")
|
||||
constant(outname="a.b" value="B" format="jsonf")
|
||||
}
|
||||
|
||||
local4.* action(type="omfile" file=`echo $RSYSLOG_OUT_LOG` template="nested_fallback")
|
||||
'
|
||||
|
||||
startup
|
||||
injectmsg 0 1
|
||||
shutdown_when_empty
|
||||
wait_shutdown
|
||||
|
||||
python3 - "$RSYSLOG_OUT_LOG" <<'PY'
|
||||
import json
|
||||
import sys
|
||||
|
||||
with open(sys.argv[1], 'r', encoding='utf-8') as fh:
|
||||
actual = json.loads(fh.read())
|
||||
|
||||
expected = {"a": "A", "a.b": "B"}
|
||||
if actual != expected:
|
||||
print('invalid fallback JSON generated')
|
||||
print('actual:', actual)
|
||||
print('expected:', expected)
|
||||
sys.exit(1)
|
||||
PY
|
||||
exit_test
|
||||
Loading…
x
Reference in New Issue
Block a user