Skip to content

Commit

Permalink
Check for subject being just -value / -key
Browse files Browse the repository at this point in the history
Such topic is probably illegal, but let's make the code immune to it
anyway.
  • Loading branch information
findepi committed Mar 23, 2021
1 parent 0ca1b66 commit 741ff8f
Showing 1 changed file with 11 additions and 4 deletions.
Expand Up @@ -41,6 +41,7 @@
import java.util.Set;
import java.util.function.Supplier;

import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.base.Preconditions.checkState;
import static com.google.common.base.Suppliers.memoizeWithExpiration;
import static com.google.common.collect.ImmutableSet.toImmutableSet;
Expand Down Expand Up @@ -272,17 +273,23 @@ public Set<SchemaTableName> listTables()
private static boolean isValidSubject(String subject)
{
requireNonNull(subject, "subject is null");
return subject.endsWith(VALUE_SUFFIX) || subject.endsWith(KEY_SUFFIX);
return (subject.endsWith(VALUE_SUFFIX) && subject.length() > VALUE_SUFFIX.length())
|| (subject.endsWith(KEY_SUFFIX) && subject.length() > KEY_SUFFIX.length());
}

private static String extractTopicFromSubject(String subject)
{
requireNonNull(subject, "subject is null");
String topic;
if (subject.endsWith(VALUE_SUFFIX)) {
return subject.substring(0, subject.length() - VALUE_SUFFIX.length());
topic = subject.substring(0, subject.length() - VALUE_SUFFIX.length());
}
checkState(subject.endsWith(KEY_SUFFIX), "Unexpected subject name %s", subject);
return subject.substring(0, subject.length() - KEY_SUFFIX.length());
else {
checkState(subject.endsWith(KEY_SUFFIX), "Unexpected subject name %s", subject);
topic = subject.substring(0, subject.length() - KEY_SUFFIX.length());
}
checkArgument(!topic.isEmpty(), "Unexpected subject name %s", subject);
return topic;
}

private static Optional<String> getKeySubjectFromTopic(String topic, Collection<String> subjectsForTopic)
Expand Down

0 comments on commit 741ff8f

Please sign in to comment.