Skip to content

Commit 2d30895

Browse files
authored
Property validation (#180)
* Stop warning when null property values are instrumented * Allow for objects nested within arrays
1 parent 44d637d commit 2d30895

File tree

4 files changed

+24
-21
lines changed

4 files changed

+24
-21
lines changed

src/utils.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ var validateProperties = function validateProperties(properties) {
133133
};
134134

135135
var invalidValueTypes = [
136-
'null', 'nan', 'undefined', 'function', 'arguments', 'regexp', 'element'
136+
'nan', 'undefined', 'function', 'arguments', 'regexp', 'element'
137137
];
138138

139139
var validatePropertyValue = function validatePropertyValue(key, value) {
@@ -150,11 +150,14 @@ var validatePropertyValue = function validatePropertyValue(key, value) {
150150
for (var i = 0; i < value.length; i++) {
151151
var element = value[i];
152152
var elemType = type(element);
153-
if (elemType === 'array' || elemType === 'object') {
153+
if (elemType === 'array') {
154154
log.warn('WARNING: Cannot have ' + elemType + ' nested in an array property value, skipping');
155155
continue;
156+
} else if (elemType === 'object') {
157+
arrayCopy.push(validateProperties(element));
158+
} else {
159+
arrayCopy.push(validatePropertyValue(key, element));
156160
}
157-
arrayCopy.push(validatePropertyValue(key, element));
158161
}
159162
value = arrayCopy;
160163
} else if (valueType === 'object') {

test/amplitude-client.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -575,9 +575,9 @@ describe('AmplitudeClient', function() {
575575
'bool': true,
576576
'string': 'test',
577577
'array': [0, 1, 2, '3'],
578-
'nested_array': ['a'],
578+
'nested_array': ['a', {'key':'value'}],
579579
'object': {'key':'value'},
580-
'nested_object': {'k':'v', 'l':[0,1], 'o':{'k2':'v2', 'l2': ['e2']}}
580+
'nested_object': {'k':'v', 'l':[0,1], 'o':{'k2':'v2', 'l2': ['e2', {'k3':'v3'}]}}
581581
}
582582

583583
// check that event loaded into memory
@@ -604,9 +604,9 @@ describe('AmplitudeClient', function() {
604604
'bool': true,
605605
'string': 'test',
606606
'array': [0, 1, 2, '3'],
607-
'nested_array': ['a'],
607+
'nested_array': ['a', {'key':'value'}],
608608
'object': {'key':'value'},
609-
'nested_object': {'k':'v', 'l':[0,1], 'o':{'k2':'v2', 'l2': ['e2']}}
609+
'nested_object': {'k':'v', 'l':[0,1], 'o':{'k2':'v2', 'l2': ['e2', {'k3':'v3'}]}}
610610
}
611611

612612
// check that event loaded into memory
@@ -710,7 +710,7 @@ it ('should load saved events from localStorage new keys and send events', funct
710710
'bool': true,
711711
'string': 'test',
712712
'array': [0, 1, 2, '3'],
713-
'nested_array': ['a'],
713+
'nested_array': ['a', {'key':'value'}],
714714
'object': {
715715
'key': 'value'
716716
},
@@ -719,7 +719,7 @@ it ('should load saved events from localStorage new keys and send events', funct
719719
'l': [0, 1],
720720
'o': {
721721
'k2': 'v2',
722-
'l2': ['e2']
722+
'l2': ['e2', {'k3':'v3'}]
723723
}
724724
}
725725
}
@@ -2348,9 +2348,9 @@ describe('setVersionName', function() {
23482348
'error': 'Error: oops',
23492349
'string': 'test',
23502350
'array': [0, 1, 2, '3'],
2351-
'nested_array': ['a'],
2351+
'nested_array': ['a', {'key': 'value'}],
23522352
'object': {'key':'value', '15':'Error: oops'},
2353-
'nested_object': {'k':'v', 'l':[0,1], 'o':{'k2':'v2', 'l2': ['e2']}}
2353+
'nested_object': {'k':'v', 'l':[0,1], 'o':{'k2':'v2', 'l2': ['e2', {'k3': 'v3'}]}}
23542354
});
23552355
});
23562356

test/amplitude.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -570,9 +570,9 @@ describe('Amplitude', function() {
570570
'bool': true,
571571
'string': 'test',
572572
'array': [0, 1, 2, '3'],
573-
'nested_array': ['a'],
573+
'nested_array': ['a', {'key':'value'}],
574574
'object': {'key':'value'},
575-
'nested_object': {'k':'v', 'l':[0,1], 'o':{'k2':'v2', 'l2': ['e2']}}
575+
'nested_object': {'k':'v', 'l':[0,1], 'o':{'k2':'v2', 'l2': ['e2', {'k3':'v3'}]}}
576576
}
577577

578578
// check that event loaded into memory
@@ -599,9 +599,9 @@ describe('Amplitude', function() {
599599
'bool': true,
600600
'string': 'test',
601601
'array': [0, 1, 2, '3'],
602-
'nested_array': ['a'],
602+
'nested_array': ['a', {'key':'value'}],
603603
'object': {'key':'value'},
604-
'nested_object': {'k':'v', 'l':[0,1], 'o':{'k2':'v2', 'l2': ['e2']}}
604+
'nested_object': {'k':'v', 'l':[0,1], 'o':{'k2':'v2', 'l2': ['e2', {'k3':'v3'}]}}
605605
}
606606

607607
// check that event loaded into memory
@@ -669,7 +669,7 @@ describe('Amplitude', function() {
669669
'bool': true,
670670
'string': 'test',
671671
'array': [0, 1, 2, '3'],
672-
'nested_array': ['a'],
672+
'nested_array': ['a', {'key':'value'}],
673673
'object': {
674674
'key': 'value'
675675
},
@@ -678,7 +678,7 @@ describe('Amplitude', function() {
678678
'l': [0, 1],
679679
'o': {
680680
'k2': 'v2',
681-
'l2': ['e2']
681+
'l2': ['e2', {'k3':'v3'}]
682682
}
683683
}
684684
}
@@ -1969,9 +1969,9 @@ describe('setVersionName', function() {
19691969
'error': 'Error: oops',
19701970
'string': 'test',
19711971
'array': [0, 1, 2, '3'],
1972-
'nested_array': ['a'],
1972+
'nested_array': ['a', {'key': 'value'}],
19731973
'object': {'key':'value', '15':'Error: oops'},
1974-
'nested_object': {'k':'v', 'l':[0,1], 'o':{'k2':'v2', 'l2': ['e2']}}
1974+
'nested_object': {'k':'v', 'l':[0,1], 'o':{'k2':'v2', 'l2': ['e2', {'k3': 'v3'}]}}
19751975
});
19761976
});
19771977

test/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ describe('utils', function() {
214214
'error': 'Error: oops',
215215
'string': 'test',
216216
'array': [0, 1, 2, '3'],
217-
'nested_array': ['a'],
217+
'nested_array': ['a', {'key': 'value'}],
218218
'object': {
219219
'key': 'value',
220220
'15': 'Error: oops'
@@ -224,7 +224,7 @@ describe('utils', function() {
224224
'l': [0, 1],
225225
'o': {
226226
'k2': 'v2',
227-
'l2': ['e2']
227+
'l2': ['e2', {'k3': 'v3'}]
228228
}
229229
}
230230
}

0 commit comments

Comments
 (0)