Skip to content

Commit

Permalink
Merge pull request #188 from hildjj/fix-diag-null
Browse files Browse the repository at this point in the history
Fix #187
  • Loading branch information
hildjj authored Jan 30, 2024
2 parents 9ae2526 + c71b7b5 commit 9733408
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module.exports = {
],
rules: {
'no-empty': ['error', {allowEmptyCatch: true}],
'jsdoc/imports-as-dependencies': 'off',
},
overrides: [
{
Expand Down
2 changes: 1 addition & 1 deletion packages/cbor-web/dist/cbor.js

Large diffs are not rendered by default.

6 changes: 4 additions & 2 deletions packages/cbor/lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,15 @@ exports.cborValueToString = function cborValueToString(val, float_bytes = -1) {
return (float_bytes > 0) ? `${s}_${float_bytes}` : s
}
case 'object': {
// A null should be caught above
if (!val) {
return 'null'
}
const buf = exports.bufferishToBuffer(val)
if (buf) {
const hex = buf.toString('hex')
return (float_bytes === -Infinity) ? hex : `h'${hex}'`
}
if (typeof val[Symbol.for('nodejs.util.inspect.custom')] === 'function') {
if (val && typeof val[Symbol.for('nodejs.util.inspect.custom')] === 'function') {
return val[Symbol.for('nodejs.util.inspect.custom')]()
}
// Shouldn't get non-empty arrays here
Expand Down
5 changes: 4 additions & 1 deletion packages/cbor/test/cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,10 @@ exports.good = [
18 -- Bytes, length: 24
000000000000000100000000000000020000000000000003 -- 000000000000000100000000000000020000000000000003
0xd8435818000000000000000100000000000000020000000000000003`]),

[[null], '[null]', `
81 -- Array, 1 item
f6 -- [0], null
0x81f6`],
]

exports.encodeGood = [
Expand Down
6 changes: 3 additions & 3 deletions packages/cbor/test/tagged.ava.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ test('Typed Arrays', t => {
})

test('null converter', t => {
const buf = Buffer.from('c100', 'hex');
t.deepEqual(cbor.decode(buf), new Date(0));
t.deepEqual(cbor.decode(buf, {tags: {1: null}}), new cbor.Tagged(1, 0));
const buf = Buffer.from('c100', 'hex')
t.deepEqual(cbor.decode(buf), new Date(0))
t.deepEqual(cbor.decode(buf, {tags: {1: null}}), new cbor.Tagged(1, 0))
})

0 comments on commit 9733408

Please sign in to comment.