From f7ac9b2f1d65a6aedb3203e19a909931aad24f2a Mon Sep 17 00:00:00 2001 From: Roberto Cortez Date: Mon, 29 Aug 2022 21:24:21 +0100 Subject: [PATCH] Only add split segments valid numeric indexes (#805) --- implementation/src/main/java/io/smallrye/config/KeyMap.java | 2 +- implementation/src/test/java/io/smallrye/config/KeyMapTest.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/implementation/src/main/java/io/smallrye/config/KeyMap.java b/implementation/src/main/java/io/smallrye/config/KeyMap.java index 8d0b8ebab..5d1ea994a 100644 --- a/implementation/src/main/java/io/smallrye/config/KeyMap.java +++ b/implementation/src/main/java/io/smallrye/config/KeyMap.java @@ -211,7 +211,7 @@ private KeyMap getNext(final String seg) { return getOrCreateAny(); } else if (seg.endsWith("]")) { int begin = seg.lastIndexOf('['); - if (begin != -1) { + if (begin != -1 && isValidIndex(seg, begin)) { String index = seg.substring(begin + 1, seg.length() - 1); String name = seg.substring(0, begin); KeyMap next; diff --git a/implementation/src/test/java/io/smallrye/config/KeyMapTest.java b/implementation/src/test/java/io/smallrye/config/KeyMapTest.java index 8d2bc7e82..b2d783e00 100644 --- a/implementation/src/test/java/io/smallrye/config/KeyMapTest.java +++ b/implementation/src/test/java/io/smallrye/config/KeyMapTest.java @@ -202,7 +202,9 @@ void putAllAny() { void map() { KeyMap map = new KeyMap<>(); map.findOrAdd("map.roles.*[*]").putRootValue("foo"); + map.findOrAdd("map.threadpool.config[customPool].id").putRootValue("customPool"); assertEquals("foo", map.findRootValue("map.roles.user[0]")); + assertEquals("customPool", map.findRootValue("map.threadpool.config[customPool].id")); } }