From 6dd96bec967a3e6ba4f46fef227db099df05982e Mon Sep 17 00:00:00 2001 From: Krishna Rajendran Date: Thu, 28 Mar 2019 11:34:40 -0700 Subject: [PATCH 1/2] Stop warning when null property values are instrumented --- src/utils.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utils.js b/src/utils.js index 1f715be7..aaf33fce 100644 --- a/src/utils.js +++ b/src/utils.js @@ -133,7 +133,7 @@ var validateProperties = function validateProperties(properties) { }; var invalidValueTypes = [ - 'null', 'nan', 'undefined', 'function', 'arguments', 'regexp', 'element' + 'nan', 'undefined', 'function', 'arguments', 'regexp', 'element' ]; var validatePropertyValue = function validatePropertyValue(key, value) { From 228b9f1c7c327ca032550b916bcdf9971950b666 Mon Sep 17 00:00:00 2001 From: Krishna Rajendran Date: Thu, 28 Mar 2019 11:35:10 -0700 Subject: [PATCH 2/2] Allow for objects nested within arrays --- src/utils.js | 7 +++++-- test/amplitude-client.js | 16 ++++++++-------- test/amplitude.js | 16 ++++++++-------- test/utils.js | 4 ++-- 4 files changed, 23 insertions(+), 20 deletions(-) diff --git a/src/utils.js b/src/utils.js index aaf33fce..3368deae 100644 --- a/src/utils.js +++ b/src/utils.js @@ -150,11 +150,14 @@ var validatePropertyValue = function validatePropertyValue(key, value) { for (var i = 0; i < value.length; i++) { var element = value[i]; var elemType = type(element); - if (elemType === 'array' || elemType === 'object') { + if (elemType === 'array') { log.warn('WARNING: Cannot have ' + elemType + ' nested in an array property value, skipping'); continue; + } else if (elemType === 'object') { + arrayCopy.push(validateProperties(element)); + } else { + arrayCopy.push(validatePropertyValue(key, element)); } - arrayCopy.push(validatePropertyValue(key, element)); } value = arrayCopy; } else if (valueType === 'object') { diff --git a/test/amplitude-client.js b/test/amplitude-client.js index 551a6b60..fa87ef09 100644 --- a/test/amplitude-client.js +++ b/test/amplitude-client.js @@ -575,9 +575,9 @@ describe('AmplitudeClient', function() { 'bool': true, 'string': 'test', 'array': [0, 1, 2, '3'], - 'nested_array': ['a'], + 'nested_array': ['a', {'key':'value'}], 'object': {'key':'value'}, - 'nested_object': {'k':'v', 'l':[0,1], 'o':{'k2':'v2', 'l2': ['e2']}} + 'nested_object': {'k':'v', 'l':[0,1], 'o':{'k2':'v2', 'l2': ['e2', {'k3':'v3'}]}} } // check that event loaded into memory @@ -604,9 +604,9 @@ describe('AmplitudeClient', function() { 'bool': true, 'string': 'test', 'array': [0, 1, 2, '3'], - 'nested_array': ['a'], + 'nested_array': ['a', {'key':'value'}], 'object': {'key':'value'}, - 'nested_object': {'k':'v', 'l':[0,1], 'o':{'k2':'v2', 'l2': ['e2']}} + 'nested_object': {'k':'v', 'l':[0,1], 'o':{'k2':'v2', 'l2': ['e2', {'k3':'v3'}]}} } // check that event loaded into memory @@ -710,7 +710,7 @@ it ('should load saved events from localStorage new keys and send events', funct 'bool': true, 'string': 'test', 'array': [0, 1, 2, '3'], - 'nested_array': ['a'], + 'nested_array': ['a', {'key':'value'}], 'object': { 'key': 'value' }, @@ -719,7 +719,7 @@ it ('should load saved events from localStorage new keys and send events', funct 'l': [0, 1], 'o': { 'k2': 'v2', - 'l2': ['e2'] + 'l2': ['e2', {'k3':'v3'}] } } } @@ -2348,9 +2348,9 @@ describe('setVersionName', function() { 'error': 'Error: oops', 'string': 'test', 'array': [0, 1, 2, '3'], - 'nested_array': ['a'], + 'nested_array': ['a', {'key': 'value'}], 'object': {'key':'value', '15':'Error: oops'}, - 'nested_object': {'k':'v', 'l':[0,1], 'o':{'k2':'v2', 'l2': ['e2']}} + 'nested_object': {'k':'v', 'l':[0,1], 'o':{'k2':'v2', 'l2': ['e2', {'k3': 'v3'}]}} }); }); diff --git a/test/amplitude.js b/test/amplitude.js index d73f9a04..34dc7cd7 100644 --- a/test/amplitude.js +++ b/test/amplitude.js @@ -570,9 +570,9 @@ describe('Amplitude', function() { 'bool': true, 'string': 'test', 'array': [0, 1, 2, '3'], - 'nested_array': ['a'], + 'nested_array': ['a', {'key':'value'}], 'object': {'key':'value'}, - 'nested_object': {'k':'v', 'l':[0,1], 'o':{'k2':'v2', 'l2': ['e2']}} + 'nested_object': {'k':'v', 'l':[0,1], 'o':{'k2':'v2', 'l2': ['e2', {'k3':'v3'}]}} } // check that event loaded into memory @@ -599,9 +599,9 @@ describe('Amplitude', function() { 'bool': true, 'string': 'test', 'array': [0, 1, 2, '3'], - 'nested_array': ['a'], + 'nested_array': ['a', {'key':'value'}], 'object': {'key':'value'}, - 'nested_object': {'k':'v', 'l':[0,1], 'o':{'k2':'v2', 'l2': ['e2']}} + 'nested_object': {'k':'v', 'l':[0,1], 'o':{'k2':'v2', 'l2': ['e2', {'k3':'v3'}]}} } // check that event loaded into memory @@ -669,7 +669,7 @@ describe('Amplitude', function() { 'bool': true, 'string': 'test', 'array': [0, 1, 2, '3'], - 'nested_array': ['a'], + 'nested_array': ['a', {'key':'value'}], 'object': { 'key': 'value' }, @@ -678,7 +678,7 @@ describe('Amplitude', function() { 'l': [0, 1], 'o': { 'k2': 'v2', - 'l2': ['e2'] + 'l2': ['e2', {'k3':'v3'}] } } } @@ -1969,9 +1969,9 @@ describe('setVersionName', function() { 'error': 'Error: oops', 'string': 'test', 'array': [0, 1, 2, '3'], - 'nested_array': ['a'], + 'nested_array': ['a', {'key': 'value'}], 'object': {'key':'value', '15':'Error: oops'}, - 'nested_object': {'k':'v', 'l':[0,1], 'o':{'k2':'v2', 'l2': ['e2']}} + 'nested_object': {'k':'v', 'l':[0,1], 'o':{'k2':'v2', 'l2': ['e2', {'k3': 'v3'}]}} }); }); diff --git a/test/utils.js b/test/utils.js index 270c6cce..eb91c91a 100644 --- a/test/utils.js +++ b/test/utils.js @@ -214,7 +214,7 @@ describe('utils', function() { 'error': 'Error: oops', 'string': 'test', 'array': [0, 1, 2, '3'], - 'nested_array': ['a'], + 'nested_array': ['a', {'key': 'value'}], 'object': { 'key': 'value', '15': 'Error: oops' @@ -224,7 +224,7 @@ describe('utils', function() { 'l': [0, 1], 'o': { 'k2': 'v2', - 'l2': ['e2'] + 'l2': ['e2', {'k3': 'v3'}] } } }