Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@
public class Event implements Serializable {

public static final String LOGTAG = "NosaraEvent";
private static final String EVENT_NAME_REGEXP = "^[a-z_][a-z0-9_]*$";
private static final String EVENT_NAME_REGEXP = "^(([a-z0-9]+)_){2}([a-z0-9_]+)$";
private static final Pattern eventNameRegExpPattern = Pattern.compile(EVENT_NAME_REGEXP);

private static final String PROPERTY_NAME_REGEXP = "^[a-z_][a-z0-9_]*$";
private static final Pattern propertyNameRegExpPattern = Pattern.compile(PROPERTY_NAME_REGEXP);

private final String mEventName;
private final String mUser;
private final String mUserAgent;
Expand Down Expand Up @@ -122,6 +125,11 @@ public boolean addCustomEventProperty(String key, Object value) {
Log.w(LOGTAG, "Properties should have lowercase name: "+ key);
}

if (key.startsWith("_")) {
Log.e(LOGTAG, "Cannot add the property: " + key + " to the event. Leading underscores are reserved.");
return false;
}

if (MessageBuilder.isReservedKeyword(key)) {
Log.e(LOGTAG, "Cannot add the property: " + key + " to the event. It's a reserved keyword.");
return false;
Expand All @@ -131,9 +139,9 @@ public boolean addCustomEventProperty(String key, Object value) {
key.equals(MessageBuilder.ALIAS_USER_ANONID_PROP_NAME)) {
// We need to exclude the validation on the property "anonId" for the event "_aliasUser".
} else {
Matcher matcher = eventNameRegExpPattern.matcher(key);
Matcher matcher = propertyNameRegExpPattern.matcher(key);
if (!matcher.matches()) {
Log.e(LOGTAG, "Cannot add the property: " + key + " to the event. Property name must match: " + EVENT_NAME_REGEXP);
Log.e(LOGTAG, "Cannot add the property: " + key + " to the event. Property name must match: " + PROPERTY_NAME_REGEXP);
return false;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ public void track(String eventName, JSONObject customProps, String user, NosaraU
public void trackAliasUser(String user, String anonUser) {
JSONObject customProps = new JSONObject();
try {
customProps.put("anonId", anonUser);
customProps.put(MessageBuilder.ALIAS_USER_ANONID_PROP_NAME, anonUser);
} catch (JSONException e) {
Log.e(LOGTAG, "Cannot track _aliasUser with the following anonUser " + anonUser);
return;
Expand Down