aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2023-03-30 16:45:23 +0200
committerGitHub <noreply@github.com>2023-03-30 16:45:23 +0200
commit25d8b632ee1ebaf42488810e15c9297474e2d905 (patch)
tree88fcc037875e05d1108794067a46c140d095f0fd
parentdb06ad61bdb8eac1d35800eea6b5cae56e392e1d (diff)
parentaf2a2f12e6e220aca770ab2e342ca50240681d0d (diff)
Merge pull request #26653 from vespa-engine/jonmv/forbid-compound-names-with-illegal-children
Forbid compound names whose children are illegal
-rw-r--r--container-core/src/main/java/com/yahoo/processing/request/CompoundName.java16
-rw-r--r--container-core/src/test/java/com/yahoo/processing/request/CompoundNameTestCase.java16
2 files changed, 24 insertions, 8 deletions
diff --git a/container-core/src/main/java/com/yahoo/processing/request/CompoundName.java b/container-core/src/main/java/com/yahoo/processing/request/CompoundName.java
index 51f7ae040eb..80a6ff1e4bf 100644
--- a/container-core/src/main/java/com/yahoo/processing/request/CompoundName.java
+++ b/container-core/src/main/java/com/yahoo/processing/request/CompoundName.java
@@ -94,16 +94,16 @@ public final class CompoundName {
int start = 0, end = i == 0 ? -1 : children[0].name.length();
for (int j = 0; j + i < children.length; j++) {
end += compounds[j + i].length() + 1;
+ if (end == start) throw new IllegalArgumentException("'" + name + "' is not a legal compound name. " +
+ "Consecutive, leading or trailing dots are not allowed.");
String subName = this.name.substring(start, end);
CompoundName cached = cache.get(subName);
- children[j] = start == end ? empty
- : cached != null
- ? cached
- : new CompoundName(subName,
- this.lowerCasedName.substring(start, end),
- Arrays.copyOfRange(compounds, j, j + i + 1),
- i == 0 ? empty : children[j + 1],
- i == 0 ? empty : children[j]);
+ children[j] = cached != null ? cached
+ : new CompoundName(subName,
+ this.lowerCasedName.substring(start, end),
+ Arrays.copyOfRange(compounds, j, j + i + 1),
+ i == 0 ? empty : children[j + 1],
+ i == 0 ? empty : children[j]);
if (useCache && cached == null) cache.put(subName, children[j]);
start += compounds[j].length() + 1;
}
diff --git a/container-core/src/test/java/com/yahoo/processing/request/CompoundNameTestCase.java b/container-core/src/test/java/com/yahoo/processing/request/CompoundNameTestCase.java
index 35e7ef84756..c0aece582de 100644
--- a/container-core/src/test/java/com/yahoo/processing/request/CompoundNameTestCase.java
+++ b/container-core/src/test/java/com/yahoo/processing/request/CompoundNameTestCase.java
@@ -78,6 +78,22 @@ public class CompoundNameTestCase {
}
@Test
+ void testIllegalCompound() {
+ assertEquals("'a.' is not a legal compound name. Names can not end with a dot.",
+ assertThrows(IllegalArgumentException.class,
+ () -> CompoundName.from("a."))
+ .getMessage());
+ assertEquals("'.b' is not a legal compound name. Consecutive, leading or trailing dots are not allowed.",
+ assertThrows(IllegalArgumentException.class,
+ () -> CompoundName.from(".b"))
+ .getMessage());
+ assertEquals("'a..b' is not a legal compound name. Consecutive, leading or trailing dots are not allowed.",
+ assertThrows(IllegalArgumentException.class,
+ () -> CompoundName.from("a..b"))
+ .getMessage());
+ }
+
+ @Test
void testFromComponents() {
verifyStrict("a", CompoundName.fromComponents("a"));
verifyStrict("a.b", CompoundName.fromComponents("a", "b"));