Fix isParent method to correctly identify FQN parent-child relationships (#17208)

This commit is contained in:
sonika-shah 2024-07-27 20:52:06 +05:30 committed by GitHub
parent 87c302ebf7
commit e93bf7024f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 4 additions and 1 deletions

View File

@ -117,7 +117,9 @@ public class FullyQualifiedName {
public static boolean isParent(String childFqn, String parentFqn) {
// Returns true if the childFqn is indeed the child of parentFqn
return childFqn.startsWith(parentFqn) && childFqn.length() > parentFqn.length();
// Adding "." ensures that we are checking for a true parent-child relationship
// For example, "a.b.c" should be a child of "a.b" but "a.b c" should not be a child of "a.b"
return childFqn.startsWith(parentFqn + ".") && childFqn.length() > parentFqn.length();
}
private static class SplitListener extends FqnBaseListener {

View File

@ -103,5 +103,6 @@ class FullyQualifiedNameTest {
assertFalse(FullyQualifiedName.isParent("a", "a.b.c"));
assertFalse(FullyQualifiedName.isParent("a.b", "a.b.c"));
assertFalse(FullyQualifiedName.isParent("a.b.c", "a.b.c"));
assertFalse(FullyQualifiedName.isParent("a.b c", "a.b"));
}
}