Skip to content

Commit

Permalink
fix!: reject duplicate map keys
Browse files Browse the repository at this point in the history
  • Loading branch information
rvagg committed Jan 6, 2023
1 parent b75bf42 commit 2e90e34
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@
"dep-check": "aegir dep-check"
},
"dependencies": {
"cborg": "^1.6.0",
"cborg": "^1.10.0",
"multiformats": "^11.0.0"
},
"devDependencies": {
Expand Down
1 change: 1 addition & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ const decodeOptions = {
// safe-integer range, which may surprise users
strict: true,
useMaps: false,
rejectDuplicateMapKeys: true,
/** @type {import('cborg').TagDecoder[]} */
tags: []
}
Expand Down
5 changes: 5 additions & 0 deletions test/test-basics.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,4 +176,9 @@ describe('dag-cbor', () => {
decoded = decode(encoded)
same({ foo: 'bar', baz: null }, decoded)
})

test('reject duplicate map keys', () => {
const encoded = bytes.fromHex('a3636261720363666f6f0163666f6f02')
assert.throws(() => decode(encoded), /CBOR decode error: found repeat map key "foo"/)
})
})

0 comments on commit 2e90e34

Please sign in to comment.