Skip to content

Commit

Permalink
use json-stringify-safe to avoid stable algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
mcollina committed Jul 11, 2021
1 parent 6817a78 commit e7c6319
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion lib/tools.js
Expand Up @@ -5,7 +5,7 @@
const format = require('quick-format-unescaped')
const { mapHttpRequest, mapHttpResponse } = require('pino-std-serializers')
const SonicBoom = require('sonic-boom')
const stringifySafe = require('safe-stable-stringify')
const stringifySafe = require('json-stringify-safe')
const {
lsCacheSym,
chindingsSym,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -91,8 +91,8 @@
},
"dependencies": {
"fast-redact": "^3.0.0",
"safe-stable-stringify": "^1.0.0",
"flatstr": "^1.0.12",
"json-stringify-safe": "^5.0.1",
"pino-std-serializers": "^3.1.0",
"quick-format-unescaped": "^4.0.3",
"sonic-boom": "^1.0.2"
Expand Down
9 changes: 4 additions & 5 deletions test/basic.test.js
Expand Up @@ -592,19 +592,18 @@ test('children with same names render in correct order', async ({ equal }) => {
equal(a, 3, 'last logged object takes precedence')
})

// https://github.com/pinojs/pino/pull/251 - use this.stringify
test('use `fast-safe-stringify` to avoid circular dependencies', async ({ same }) => {
test('use `json-stringify-safe` to avoid circular dependencies', async ({ same }) => {
const stream = sink()
const root = pino(stream)
// circular depth
const obj = {}
obj.a = obj
root.info(obj)
const { a } = await once(stream, 'data')
same(a, { a: '[Circular]' })
same(a, { a: '[Circular ~]' })
})

test('fast-safe-stringify must be used when interpolating', async (t) => {
test('json-stringify-safe must be used when interpolating', async (t) => {
const stream = sink()
const instance = pino(stream)

Expand All @@ -613,7 +612,7 @@ test('fast-safe-stringify must be used when interpolating', async (t) => {
instance.info('test %j', o)

const { msg } = await once(stream, 'data')
t.equal(msg, 'test {"a":{"b":{"c":"[Circular]"}}}')
t.equal(msg, 'test {"a":{"b":{"c":"[Circular ~.a.b]"}}}')
})

test('throws when setting useOnlyCustomLevels without customLevels', async ({ throws }) => {
Expand Down

0 comments on commit e7c6319

Please sign in to comment.