diff options
author | jonmv <venstad@gmail.com> | 2023-03-30 15:43:42 +0200 |
---|---|---|
committer | jonmv <venstad@gmail.com> | 2023-03-30 15:43:42 +0200 |
commit | af2a2f12e6e220aca770ab2e342ca50240681d0d (patch) | |
tree | 88fcc037875e05d1108794067a46c140d095f0fd /container-core | |
parent | db06ad61bdb8eac1d35800eea6b5cae56e392e1d (diff) |
Forbid compound names whose children are illegal
Diffstat (limited to 'container-core')
-rw-r--r-- | container-core/src/main/java/com/yahoo/processing/request/CompoundName.java | 16 | ||||
-rw-r--r-- | container-core/src/test/java/com/yahoo/processing/request/CompoundNameTestCase.java | 16 |
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")); |