Skip to content
Merged
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 @@ -23,10 +23,16 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/** An abstract class providing an interface to validate PerfMetric */
public abstract class PerfMetricValidator {

// Regex to validate Attribute key
private static final Pattern ATTRIBUTE_KEY_PATTERN =
Pattern.compile("^(?!(firebase_|google_|ga_))[A-Za-z][A-Za-z_0-9]*");

/**
* Creates a list of PerfMetricValidator classes based on the contents of PerfMetric
*
Expand Down Expand Up @@ -164,7 +170,8 @@ public static void validateAttribute(@NonNull String key, @NonNull String value)
Constants.MAX_ATTRIBUTE_VALUE_LENGTH));
}

if (!key.matches("^(?!(firebase_|google_|ga_))[A-Za-z][A-Za-z_0-9]*")) {
Matcher attributeKeyMatcher = ATTRIBUTE_KEY_PATTERN.matcher(key);
if (!attributeKeyMatcher.matches()) {
throw new IllegalArgumentException(
"Attribute key must start with letter, must only contain alphanumeric characters and"
+ " underscore and must not start with \"firebase_\", \"google_\" and \"ga_");
Expand Down
Loading