Merge pull request #18 from zeit/structured-data-multi-values

Allow to set multiple values for a field of structured data on RFC5424
This commit is contained in:
Naoyuki Kanezawa 2020-01-28 17:49:45 +09:00 committed by GitHub
commit fa3eb3ff65
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 5 deletions

View File

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

View File

@ -456,7 +456,7 @@ describe('RFC5424 Class Tests', () => {
structuredData: {
"hi@32473": {
foo: 1,
bar: 2
bar: [2, 3]
},
escape: {
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', () => {
const rfc5424 = new SyslogPro.RFC5424({