allow to set multple values for a field of structured data

This commit is contained in:
nkzawa 2020-01-28 17:43:26 +09:00
parent 094874fc29
commit 83c1ffa47e
2 changed files with 7 additions and 5 deletions

View File

@ -1452,9 +1452,11 @@ export class RFC5424 extends RFC {
return '[' + [ return '[' + [
sdId, sdId,
...Object.entries(sdParam) ...Object.entries(sdParam)
.map(([name, value]) => .reduce((array, [name, value]) => [
`${name}="${RFC5424.escapeParamValue(value)}"` ...array,
), ...(Array.isArray(value) ? value : [value])
.map((v) => `${name}="${RFC5424.escapeParamValue(v)}"`),
], []),
].join(' ') + ']'; ].join(' ') + ']';
}).join(''); }).join('');
} }

View File

@ -456,7 +456,7 @@ describe('RFC5424 Class Tests', () => {
structuredData: { structuredData: {
"hi@32473": { "hi@32473": {
foo: 1, foo: 1,
bar: 2 bar: [2, 3]
}, },
escape: { escape: {
quoteCharacter: '"', quoteCharacter: '"',
@ -465,7 +465,7 @@ describe('RFC5424 Class Tests', () => {
} }
} }
}); });
expect(result).toMatch(/^<190>1 \S+ \S+ - - - \[hi@32473 foo="1" bar="2"\]\[escape quoteCharacter="\\"" backslack="\\\\" closingBrace="\\]"\] BOMhello\n$/); expect(result).toMatch(/^<190>1 \S+ \S+ - - - \[hi@32473 foo="1" bar="2" bar="3"\]\[escape quoteCharacter="\\"" backslack="\\\\" closingBrace="\\]"\] BOMhello\n$/);
}); });
test('RFC5424 BuildMessage with octet-counting', () => { test('RFC5424 BuildMessage with octet-counting', () => {
const rfc5424 = new SyslogPro.RFC5424({ const rfc5424 = new SyslogPro.RFC5424({