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 1a8ca39 commit 65a37bc
Show file tree
Hide file tree
Showing 3 changed files with 6 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.5.4",
"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 @@ -192,6 +192,7 @@ const decodeOptions = {
// safe-integer range, which may surprise users
strict: true,
useMaps: false,
rejectDuplicateMapKeys: true,
/** @type {import('cborg').TagDecoder[]} */
tags: []
}
Expand Down
4 changes: 4 additions & 0 deletions test/test-basics.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,4 +183,8 @@ describe('basic dag-json', () => {
same(bytes.isBinary(output.bytes), true)
same(CID.asCID(output.link), output.link)
})

test('reject duplicate map keys', () => {
assert.throws(() => decode(new TextEncoder().encode('{"foo":1,"foo":2,"bar":3}')), /found repeat map key "foo"/)
})
})

0 comments on commit 65a37bc

Please sign in to comment.