diff options
author | ToineSiebelink <toine.siebelink@est.tech> | 2021-03-09 15:27:06 +0000 |
---|---|---|
committer | Toine Siebelink <toine.siebelink@est.tech> | 2021-03-10 10:45:17 +0000 |
commit | 56249583ba84956886454ec0b276c743161337ac (patch) | |
tree | c018fcc9a9c24073e2769eaeb761736a5e3c7442 /cps-ri/src/main/java | |
parent | 2968b0e0037fa238c13290df43b2306524f5271b (diff) |
Fix SOnarQube bug on Regex
- Regex included unlimitted repetition is now limited to 99
99 nested yang container should sufice, in my experience in 5G 20-30 levels is the max I have seen
we can always record it as a 'known limitation'
-tried to improve the redability of the Regex using constant names
- Added edge-case senarios testing related to query regex
Issue-ID: CPS-89
Signed-off-by: ToineSiebelink <toine.siebelink@est.tech>
Change-Id: Ic3442bc8ca22fe66976948f9913e033245a0e41c
Diffstat (limited to 'cps-ri/src/main/java')
-rw-r--r-- | cps-ri/src/main/java/org/onap/cps/spi/query/CpsPathQuery.java | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/query/CpsPathQuery.java b/cps-ri/src/main/java/org/onap/cps/spi/query/CpsPathQuery.java index 54a6a96c4e..7b9bfba174 100644 --- a/cps-ri/src/main/java/org/onap/cps/spi/query/CpsPathQuery.java +++ b/cps-ri/src/main/java/org/onap/cps/spi/query/CpsPathQuery.java @@ -37,14 +37,18 @@ public class CpsPathQuery { private Object leafValue; private String endsWith; - public static final Pattern QUERY_CPS_PATH_WITH_SINGLE_LEAF_PATTERN = - Pattern.compile("((?:\\/[^\\/]+)+?)\\[\\s*@(\\S+?)\\s*=\\s*(.*?)\\s*\\]"); + private static final String NON_CAPTURING_GROUP_1_TO_99_YANG_CONTAINERS = "((?:\\/[^\\/]+){1,99})"; - public static final Pattern QUERY_CPS_PATH_ENDS_WITH_PATTERN = Pattern.compile("\\/\\/(.+)"); + private static final String YANG_LEAF_VALUE_EQUALS_CONDITION = "\\[\\s*@(\\S+?)\\s*=\\s*(.*?)\\s*\\]"; - public static final Pattern LEAF_INTEGER_VALUE_PATTERN = Pattern.compile("[-+]?\\d+"); + private static final Pattern QUERY_CPS_PATH_WITH_SINGLE_LEAF_PATTERN = + Pattern.compile(NON_CAPTURING_GROUP_1_TO_99_YANG_CONTAINERS + YANG_LEAF_VALUE_EQUALS_CONDITION); - public static final Pattern LEAF_STRING_VALUE_PATTERN = Pattern.compile("['\"](.*)['\"]"); + private static final Pattern QUERY_CPS_PATH_ENDS_WITH_PATTERN = Pattern.compile("\\/\\/(.+)"); + + private static final Pattern LEAF_INTEGER_VALUE_PATTERN = Pattern.compile("[-+]?\\d+"); + + private static final Pattern LEAF_STRING_VALUE_PATTERN = Pattern.compile("['\"](.*)['\"]"); /** * Returns a cps path query. |