Skip to content

Commit d60a443

Browse files
mnoman09thomaszurkan-optimizely
authored andcommitted
Fix: Filter Empty key attributes from payload (#222)
1 parent 8de8ff2 commit d60a443

File tree

4 files changed

+19
-0
lines changed

4 files changed

+19
-0
lines changed

core-api/src/main/java/com/optimizely/ab/event/internal/EventFactory.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,12 @@ private List<Attribute> buildAttributeList(ProjectConfig projectConfig, Map<Stri
168168
List<Attribute> attributesList = new ArrayList<Attribute>();
169169

170170
for (Map.Entry<String, ?> entry : attributes.entrySet()) {
171+
172+
//Ignore attributes with empty key
173+
if (entry.getKey().isEmpty()) {
174+
continue;
175+
}
176+
171177
// Filter down to the types of values we're allowed to track.
172178
// Don't allow Longs, BigIntegers, or BigDecimals - they /can/ theoretically be serialized as JSON numbers
173179
// but may take on values that can't be faithfully parsed by the backend.

core-api/src/test/java/com/optimizely/ab/config/ValidProjectConfigV4.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,10 @@ public class ValidProjectConfigV4 {
6161
public static final String ATTRIBUTE_DOUBLE_KEY = "doubleKey";
6262
private static final Attribute ATTRIBUTE_DOUBLE = new Attribute(ATTRIBUTE_DOUBLE_ID, ATTRIBUTE_DOUBLE_KEY);
6363

64+
private static final String ATTRIBUTE_EMPTY_KEY_ID = "808797686";
65+
public static final String ATTRIBUTE_EMPTY_KEY = "";
66+
private static final Attribute ATTRIBUTE_EMPTY = new Attribute(ATTRIBUTE_EMPTY_KEY_ID, ATTRIBUTE_EMPTY_KEY);
67+
6468
// audiences
6569
private static final String CUSTOM_ATTRIBUTE_TYPE = "custom_attribute";
6670
private static final String AUDIENCE_BOOL_ID = "3468206643";
@@ -1158,6 +1162,7 @@ public static ProjectConfig generateValidProjectConfigV4() {
11581162
attributes.add(ATTRIBUTE_BOOLEAN);
11591163
attributes.add(ATTRIBUTE_INTEGER);
11601164
attributes.add(ATTRIBUTE_DOUBLE);
1165+
attributes.add(ATTRIBUTE_EMPTY);
11611166

11621167
// list audiences
11631168
List<Audience> audiences = new ArrayList<Audience>();

core-api/src/test/java/com/optimizely/ab/event/internal/EventFactoryTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ public void createConversionEventIgnoresInvalidAndAcceptsValidAttributes() {
271271
Attribute doubleAttribute = validProjectConfig.getAttributes().get(5);
272272
Attribute integerAttribute = validProjectConfig.getAttributes().get(4);
273273
Attribute boolAttribute = validProjectConfig.getAttributes().get(3);
274+
Attribute emptyAttribute = validProjectConfig.getAttributes().get(6);
274275

275276
BigInteger bigInteger = new BigInteger("12323");
276277
BigDecimal bigDecimal = new BigDecimal("123");
@@ -288,6 +289,7 @@ public void createConversionEventIgnoresInvalidAndAcceptsValidAttributes() {
288289
attributes.put(doubleAttribute.getKey(), validDoubleAttribute);
289290
attributes.put(integerAttribute.getKey(), validIntegerAttribute);
290291
attributes.put(boolAttribute.getKey(), validBoolAttribute);
292+
attributes.put(emptyAttribute.getKey(), validBoolAttribute);
291293

292294
DecisionService decisionService = new DecisionService(
293295
mockBucketAlgorithm,
@@ -328,6 +330,8 @@ public void createConversionEventIgnoresInvalidAndAcceptsValidAttributes() {
328330
assertNotSame(feature.getValue(), bigInteger);
329331
assertNotSame(feature.getKey(), attribute2.getKey());
330332
assertNotSame(feature.getValue(), bigDecimal);
333+
assertNotSame(feature.getKey(), emptyAttribute.getKey());
334+
assertNotSame(feature.getValue(), doubleAttribute);
331335
}
332336
}
333337

core-api/src/test/resources/config/valid-project-config-v4.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@
8888
{
8989
"id": "808797686",
9090
"key": "doubleKey"
91+
},
92+
{
93+
"id": "808797686",
94+
"key": ""
9195
}
9296
],
9397
"events": [

0 commit comments

Comments
 (0)