diff --git a/src/utils.js b/src/utils.js index 1f715be7..3368deae 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) { @@ -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'}] } } }