Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

[Bug] Fix boolean parsing for yes/no string values (#3346) (#3365)

Asish Kumarf25f128671b9
diff --git a/src/processors/src/data-processor.ts b/src/processors/src/data-processor.ts
index 5b0f2af45..37920125e 100644
--- a/src/processors/src/data-processor.ts
+++ b/src/processors/src/data-processor.ts
@@ -51,7 +51,10 @@ function tryParseJsonString(str) {
export const PARSE_FIELD_VALUE_FROM_STRING = {
[ALL_FIELD_TYPES.boolean]: {
valid: (d: unknown): boolean => typeof d === 'boolean',
- parse: (d: unknown): boolean => d === 'true' || d === 'True' || d === 'TRUE' || d === '1'
+ parse: (d: unknown): boolean => {
+ const s = String(d).toLowerCase();
+ return s === 'true' || s === 'yes' || s === '1';
+ }
},
[ALL_FIELD_TYPES.integer]: {
// @ts-ignore
diff --git a/test/node/utils/data-processor-test.js b/test/node/utils/data-processor-test.js
index 599035645..040c46f2b 100644
--- a/test/node/utils/data-processor-test.js
+++ b/test/node/utils/data-processor-test.js
@@ -447,10 +447,45 @@ test('Processor -> parseCsvRowsByFieldType -> boolean', t => {
type: ALL_FIELD_TYPES.boolean
};
- const rows = [[null], ['0'], ['1'], ['True'], ['False'], ['0'], ['1'], ['true']];
+ const rows = [
+ [null],
+ ['0'],
+ ['1'],
+ ['True'],
+ ['False'],
+ ['0'],
+ ['1'],
+ ['true'],
+ ['yes'],
+ ['Yes'],
+ ['YES'],
+ ['no'],
+ ['No'],
+ ['NO'],
+ ['TRUE'],
+ ['false'],
+ ['FALSE']
+ ];
- // is parsing '' meaningful, why not false
- const expected = [[null], [false], [true], [true], [false], [false], [true], [true]];
+ const expected = [
+ [null],
+ [false],
+ [true],
+ [true],
+ [false],
+ [false],
+ [true],
+ [true],
+ [true],
+ [true],
+ [true],
+ [false],
+ [false],
+ [false],
+ [true],
+ [false],
+ [false]
+ ];
parseCsvRowsByFieldType(rows, -1, field, 0);
t.same(rows, expected, 'should parsed boolean properly');