Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding asString to the key #1779

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading