summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLee Anjella Macabuhay <lee.anjella.macabuhay@est.tech>2024-11-26 11:07:34 +0000
committerGerrit Code Review <gerrit@onap.org>2024-11-26 11:07:34 +0000
commite50b36d17de45bc64eebb305a80dc62ac4ee0928 (patch)
treebdda62a9e2ef7f32013d7a00a8af902a60820686
parent52896b8ecee8cce64519972f12b7a68351c6c1ad (diff)
parent1ea72e9c1dff6b1fcdd584362d1d2aaa1d9ce28d (diff)
Merge "[Cps Path Parser] Don't quote numbers in comparison"
-rw-r--r--cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java16
-rw-r--r--cps-path-parser/src/test/groovy/org/onap/cps/cpspath/parser/CpsPathQuerySpec.groovy8
2 files changed, 14 insertions, 10 deletions
diff --git a/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java b/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java
index ed7dbecc18..b67d70847c 100644
--- a/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java
+++ b/cps-path-parser/src/main/java/org/onap/cps/cpspath/parser/CpsPathBuilder.java
@@ -180,12 +180,12 @@ public class CpsPathBuilder extends CpsPathBaseListener {
if (!isStartOfExpression) {
currentNormalizedPathBuilder.append(" ").append(getLastElement(booleanOperators)).append(" ");
}
- currentNormalizedPathBuilder.append("@")
- .append(name)
- .append(operator)
- .append("'")
- .append(value.toString().replace("'", "''"))
- .append("'");
+ currentNormalizedPathBuilder.append("@").append(name).append(operator);
+ if (operator.equals("=")) {
+ currentNormalizedPathBuilder.append(wrapValueInSingleQuotes(value));
+ } else {
+ currentNormalizedPathBuilder.append(value);
+ }
}
private static String getLastElement(final List<String> listOfStrings) {
@@ -202,6 +202,10 @@ public class CpsPathBuilder extends CpsPathBaseListener {
}
}
+ private static String wrapValueInSingleQuotes(final Object value) {
+ return "'" + value.toString().replace("'", "''") + "'";
+ }
+
private static String stripFirstAndLastCharacter(final String wrappedString) {
return wrappedString.substring(1, wrappedString.length() - 1);
}
diff --git a/cps-path-parser/src/test/groovy/org/onap/cps/cpspath/parser/CpsPathQuerySpec.groovy b/cps-path-parser/src/test/groovy/org/onap/cps/cpspath/parser/CpsPathQuerySpec.groovy
index 16430d2fa5..a1bf28977a 100644
--- a/cps-path-parser/src/test/groovy/org/onap/cps/cpspath/parser/CpsPathQuerySpec.groovy
+++ b/cps-path-parser/src/test/groovy/org/onap/cps/cpspath/parser/CpsPathQuerySpec.groovy
@@ -87,10 +87,10 @@ class CpsPathQuerySpec extends Specification {
'yang container' | '/cps-path' || '/cps-path'
'descendant anywhere' | '//cps-path' || '//cps-path'
'descendant with leaf condition' | '//cps-path[@key=1]' || "//cps-path[@key='1']"
- 'descendant with leaf condition has ">" operator' | '//cps-path[@key>9]' || "//cps-path[@key>'9']"
- 'descendant with leaf condition has "<" operator' | '//cps-path[@key<10]' || "//cps-path[@key<'10']"
- 'descendant with leaf condition has ">=" operator' | '//cps-path[@key>=8]' || "//cps-path[@key>='8']"
- 'descendant with leaf condition has "<=" operator' | '//cps-path[@key<=12]' || "//cps-path[@key<='12']"
+ 'descendant with leaf condition has ">" operator' | '//cps-path[@key>9]' || "//cps-path[@key>9]"
+ 'descendant with leaf condition has "<" operator' | '//cps-path[@key<10]' || "//cps-path[@key<10]"
+ 'descendant with leaf condition has ">=" operator' | '//cps-path[@key>=8]' || "//cps-path[@key>=8]"
+ 'descendant with leaf condition has "<=" operator' | '//cps-path[@key<=12]' || "//cps-path[@key<=12]"
'descendant with leaf value and ancestor' | '//cps-path[@key=1]/ancestor::parent[@key=1]' || "//cps-path[@key='1']/ancestor::parent[@key='1']"
'parent & child' | '/parent/child' || '/parent/child'
'parent leaf of type Integer & child' | '/parent/child[@code=1]/child2' || "/parent/child[@code='1']/child2"