Skip to content

Commit 23dc7a6

Browse files
committed
fix issue in coerceToType where coercing false to a boolean changes it to true
1 parent 805c4ea commit 23dc7a6

3 files changed

Lines changed: 7 additions & 2 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "react-json-editor",
3-
"version": "0.2.2",
3+
"version": "0.2.3",
44
"description": "A JSON editor for ReactJS",
55
"main": "dist/index.js",
66
"scripts": {

src/lib/coerceToType.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default function coerceToType(value, nextType) {
1616
return '';
1717

1818
case 'boolean':
19-
return true;
19+
return typeof value === 'boolean' ? value : true;
2020

2121
case 'map':
2222
return {};

tests/lib/coerceToType.spec.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,9 @@ describe('coerceToType', () => {
4343
it('returns null if nextType is unknown', () => {
4444
expect(coerceToType(42, 'foo')).toBe(null);
4545
});
46+
47+
it('when coercing a boolean to boolean, returns the same value', () => {
48+
expect(coerceToType(true, 'boolean')).toEqual(true);
49+
expect(coerceToType(false, 'boolean')).toEqual(false);
50+
});
4651
});

0 commit comments

Comments
 (0)