mirror of
https://github.com/log4js-node/log4js-node.git
synced 2025-12-08 19:26:01 +00:00
fix(LoggingEvent): serde for object with null prototype
This commit is contained in:
parent
f5cac419c5
commit
e1efb82829
@ -22,7 +22,11 @@ class SerDe {
|
||||
|
||||
canSerialise(key) {
|
||||
if (typeof key === 'string') return false;
|
||||
return key in this.serMap;
|
||||
try {
|
||||
return key in this.serMap;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
serialise(key) {
|
||||
|
||||
@ -20,6 +20,8 @@ test('LoggingEvent', (batch) => {
|
||||
});
|
||||
|
||||
batch.test('should serialise to flatted', (t) => {
|
||||
const nullPrototype = Object.create(null);
|
||||
nullPrototype.hello = 'world';
|
||||
const event = new LoggingEvent(
|
||||
'cheese',
|
||||
levels.DEBUG,
|
||||
@ -33,6 +35,7 @@ test('LoggingEvent', (batch) => {
|
||||
'-Infinity',
|
||||
undefined,
|
||||
'undefined',
|
||||
nullPrototype,
|
||||
],
|
||||
{
|
||||
user: 'bob',
|
||||
@ -44,7 +47,7 @@ test('LoggingEvent', (batch) => {
|
||||
t.equal(rehydratedEvent.startTime, '2018-02-04T18:30:23.010Z');
|
||||
t.equal(rehydratedEvent.categoryName, 'cheese');
|
||||
t.equal(rehydratedEvent.level.levelStr, 'DEBUG');
|
||||
t.equal(rehydratedEvent.data.length, 9);
|
||||
t.equal(rehydratedEvent.data.length, 10);
|
||||
t.equal(rehydratedEvent.data[0], 'log message');
|
||||
t.equal(rehydratedEvent.data[1], '__LOG4JS_NaN__');
|
||||
t.equal(rehydratedEvent.data[2], 'NaN');
|
||||
@ -54,6 +57,11 @@ test('LoggingEvent', (batch) => {
|
||||
t.equal(rehydratedEvent.data[6], '-Infinity');
|
||||
t.equal(rehydratedEvent.data[7], '__LOG4JS_undefined__');
|
||||
t.equal(rehydratedEvent.data[8], 'undefined');
|
||||
t.equal(
|
||||
Object.entries(rehydratedEvent.data[9]).length,
|
||||
Object.entries(nullPrototype).length
|
||||
);
|
||||
t.equal(rehydratedEvent.data[9].hello, 'world');
|
||||
t.equal(rehydratedEvent.context.user, 'bob');
|
||||
t.end();
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user