Skip to content

Commit 9c8c599

Browse files
committed
identify should ignore invalid proxy objects
1 parent 8897161 commit 9c8c599

File tree

4 files changed

+31
-19
lines changed

4 files changed

+31
-19
lines changed

amplitude.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3311,18 +3311,22 @@ var Identify = function() {
33113311
};
33123312

33133313
Identify.prototype.fromProxyObject = function(proxyObject) {
3314-
this._addOperationsFromProxyObjectDictionary(AMP_OP_SET_ONCE, proxyObject, 'so');
3315-
this._addOperationsFromProxyObjectDictionary(AMP_OP_UNSET, proxyObject, 'u');
3316-
this._addOperationsFromProxyObjectDictionary(AMP_OP_SET, proxyObject, 's');
3317-
this._addOperationsFromProxyObjectDictionary(AMP_OP_ADD, proxyObject, 'a');
3314+
if (!('p' in proxyObject)) {
3315+
return this;
3316+
}
3317+
3318+
this._addOperationsFromProxyObjectDictionary(AMP_OP_SET_ONCE, proxyObject.p, 'so');
3319+
this._addOperationsFromProxyObjectDictionary(AMP_OP_UNSET, proxyObject.p, 'u');
3320+
this._addOperationsFromProxyObjectDictionary(AMP_OP_SET, proxyObject.p, 's');
3321+
this._addOperationsFromProxyObjectDictionary(AMP_OP_ADD, proxyObject.p, 'a');
33183322
return this;
33193323
};
33203324

3321-
Identify.prototype._addOperationsFromProxyObjectDictionary = function(operation, proxyObject, dictionary) {
3322-
if (dictionary in proxyObject.p) {
3323-
for (var key in proxyObject.p[dictionary]) {
3324-
if (proxyObject.p[dictionary].hasOwnProperty(key)) {
3325-
this._addOperation(operation, key, proxyObject.p[dictionary][key]);
3325+
Identify.prototype._addOperationsFromProxyObjectDictionary = function(operation, userPropertyOperations, dictionary) {
3326+
if (dictionary in userPropertyOperations) {
3327+
for (var key in userPropertyOperations[dictionary]) {
3328+
if (userPropertyOperations[dictionary].hasOwnProperty(key)) {
3329+
this._addOperation(operation, key, userPropertyOperations[dictionary][key]);
33263330
}
33273331
}
33283332
}

amplitude.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/identify.js

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,22 @@ var Identify = function() {
2222
};
2323

2424
Identify.prototype.fromProxyObject = function(proxyObject) {
25-
this._addOperationsFromProxyObjectDictionary(AMP_OP_SET_ONCE, proxyObject, 'so');
26-
this._addOperationsFromProxyObjectDictionary(AMP_OP_UNSET, proxyObject, 'u');
27-
this._addOperationsFromProxyObjectDictionary(AMP_OP_SET, proxyObject, 's');
28-
this._addOperationsFromProxyObjectDictionary(AMP_OP_ADD, proxyObject, 'a');
25+
if (!('p' in proxyObject)) {
26+
return this;
27+
}
28+
29+
this._addOperationsFromProxyObjectDictionary(AMP_OP_SET_ONCE, proxyObject.p, 'so');
30+
this._addOperationsFromProxyObjectDictionary(AMP_OP_UNSET, proxyObject.p, 'u');
31+
this._addOperationsFromProxyObjectDictionary(AMP_OP_SET, proxyObject.p, 's');
32+
this._addOperationsFromProxyObjectDictionary(AMP_OP_ADD, proxyObject.p, 'a');
2933
return this;
3034
};
3135

32-
Identify.prototype._addOperationsFromProxyObjectDictionary = function(operation, proxyObject, dictionary) {
33-
if (dictionary in proxyObject.p) {
34-
for (var key in proxyObject.p[dictionary]) {
35-
if (proxyObject.p[dictionary].hasOwnProperty(key)) {
36-
this._addOperation(operation, key, proxyObject.p[dictionary][key]);
36+
Identify.prototype._addOperationsFromProxyObjectDictionary = function(operation, userPropertyOperations, dictionary) {
37+
if (dictionary in userPropertyOperations) {
38+
for (var key in userPropertyOperations[dictionary]) {
39+
if (userPropertyOperations[dictionary].hasOwnProperty(key)) {
40+
this._addOperation(operation, key, userPropertyOperations[dictionary][key]);
3741
}
3842
}
3943
}

test/identify.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ describe('Identify', function() {
164164
var emptyIdentify = new Identify().fromProxyObject(emptyProxyObject);
165165
assert.deepEqual(emptyIdentify.userPropertiesOperations, {});
166166

167+
// proxy object without p dict should result in empty identify object:
168+
var emptyIdentify2 = new Identify().fromProxyObject({});
169+
assert.deepEqual(emptyIdentify2.userPropertiesOperations, {});
170+
167171
var proxyObject = {'p':{
168172
'a':{'key1': 'value1'},
169173
'u':{'key1': 'value2'},

0 commit comments

Comments
 (0)