Extract EnumListParameter values before checking for matches

Previously EnumListParameter would find a match if the parameter starts with
any of the values in the enum.  This would misfire if an enum value is a prefix
of another enum value.

Change-Id: I3dc45359afbf7483d9c16a76c0114b5c42daed83
Reviewed-on: https://dart-review.googlesource.com/c/91620
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
Jason Simmons
2019-01-31 18:30:28 +00:00
committed by commit-bot@chromium.org
parent 20fc81470e
commit aaf97448b0
+10 -12
View File
@@ -701,27 +701,25 @@ class EnumListParameter : public MethodParameter {
return -1;
}
bool valid_enum = false;
const char* id_start = cp;
while (IsEnumChar(*cp)) {
cp++;
}
if (cp == id_start) {
// Empty identifier, something like this [,].
return -1;
}
intptr_t id_len = cp - id_start;
if (enums_ != NULL) {
for (intptr_t i = 0; enums_[i] != NULL; i++) {
intptr_t len = strlen(enums_[i]);
if (strncmp(cp, enums_[i], len) == 0) {
if (len == id_len && strncmp(id_start, enums_[i], len) == 0) {
element_count++;
valid_enum = true;
cp += len;
element_allowed = false; // we need a comma first.
break;
}
}
} else {
// Allow any identifiers
const char* id_start = cp;
while (IsEnumChar(*cp)) {
cp++;
}
if (cp == id_start) {
// Empty identifier, something like this [,].
return -1;
}
}
if (!valid_enum) {
return -1;