Skip to content

Commit

Permalink
adding asString to the key (#1779)
Browse files Browse the repository at this point in the history
  • Loading branch information
tzviki authored Aug 10, 2023
1 parent 4c779a4 commit da75c01
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ function asJson (obj, msg, num, time) {
value = (stringifier || stringify)(value, stringifySafe)
}
if (value === undefined) continue
propStr += ',"' + key + '":' + value
const strKey = asString(key)
propStr += ',' + strKey + ':' + value
}
}

Expand Down
17 changes: 17 additions & 0 deletions test/basic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,23 @@ test('correctly escape msg strings with unclosed double quote', async ({ same })
})
})

test('correctly escape quote in a key', async ({ same }) => {
const stream = sink()
const instance = pino(stream)
const obj = { 'some"obj': 'world' }
instance.info(obj, 'a string')
const result = await once(stream, 'data')
delete result.time
same(result, {
level: 30,
pid,
hostname,
msg: 'a string',
'some"obj': 'world'
})
same(Object.keys(obj), ['some"obj'])
})

// https://github.com/pinojs/pino/issues/139
test('object and format string', async ({ same }) => {
const stream = sink()
Expand Down

0 comments on commit da75c01

Please sign in to comment.