Skip to content

Commit f05fe43

Browse files
bitgopatmclericcrosson-bitgo
authored andcommitted
chore: add test for decoding overlapping keys with flatten
Although it is undefined behavior to define a `flatten` codec with overlapping keys, the actual codec needs to handle arbitrary input which might have them. This commit adds a test for this, and fortunately the existing code passes.
1 parent 505f739 commit f05fe43

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

packages/io-ts-http/test/combinators.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ describe('flattened', () => {
3939

4040
it('combines with optional params', () =>
4141
assertEncodes(codec, { foo: 42 }, { test: { foo: 42 }, anotherParam: {} }));
42+
43+
it('does not get confused by overlapping extra parameters', () => {
44+
const input = {
45+
test: { foo: 42, bar: 'bad' },
46+
anotherParam: { foo: 123, bar: '123' },
47+
};
48+
const expected = { foo: 42, bar: '123' };
49+
assertDecodes(codec, input, expected);
50+
});
4251
});
4352

4453
describe('optionalized', () => {

0 commit comments

Comments
 (0)