Clean up predicates prior to xpath normalization 30/91330/2
authorTomas Cere <tomas.cere@pantheon.tech>
Wed, 15 Jul 2020 08:43:57 +0000 (10:43 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 15 Jul 2020 09:41:08 +0000 (11:41 +0200)
Path splitting is not equipped to ignore step predicates, which leads
it to do arrive at the wrong path. Remove any predicates before
embarking on resolving the reference.

JIRA: YANGTOOLS-1126
Change-Id: Ia32836ad1acec0762d9baa7ded5f65fa72f39b93
Signed-off-by: Tomas Cere <tomas.cere@pantheon.tech>
(cherry picked from commit 76fac8f8464bd072d9b26dccddb5450d3716dd51)

yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.java

index 3c94ae45248edab914c163168532e605b4e02bb5..80f9ddc9060ac27f835f0f17c4244675dee48629 100644 (file)
@@ -82,6 +82,7 @@ public final class SchemaContextUtil {
     private static final Splitter COLON_SPLITTER = Splitter.on(':');
     private static final Splitter SLASH_SPLITTER = Splitter.on('/').omitEmptyStrings();
     private static final CharMatcher SPACE = CharMatcher.is(' ');
+    private static final Pattern GROUPS_PATTERN = Pattern.compile("\\[(.*?)\\]");
 
     private SchemaContextUtil() {
         // Hidden on purpose
@@ -269,7 +270,12 @@ public final class SchemaContextUtil {
             final SchemaNode actualSchemaNode, final PathExpression relativeXPath) {
         checkState(!relativeXPath.isAbsolute(), "Revision Aware XPath MUST be relative i.e. MUST contains ../, "
                 + "for non relative Revision Aware XPath use findDataSchemaNode method");
-        return resolveRelativeXPath(context, module, relativeXPath.getOriginalString(), actualSchemaNode);
+        return resolveRelativeXPath(context, module, removePredicatesFromXpath(relativeXPath.getOriginalString()),
+                actualSchemaNode);
+    }
+
+    private static String removePredicatesFromXpath(final String xpath) {
+        return GROUPS_PATTERN.matcher(xpath).replaceAll("");
     }
 
     /**