Allow double slashes in RESTCONF URLs 44/81144/1
authorJaroslav Tóth <jtoth@frinx.io>
Mon, 25 Mar 2019 13:47:47 +0000 (14:47 +0100)
committerJaroslav Tóth <jtoth@frinx.io>
Mon, 25 Mar 2019 13:53:01 +0000 (14:53 +0100)
- Allowing of double slashes in URI - empty part of URI is ignored
  if list with one or more keys doesn't preceed it.
- Fix for old RESTCONF spec.

Change-Id: If3c4a6cd7c81d3e09500f74f6da3843bb525fc19
JIRA: NETCONF-24
Signed-off-by: Jaroslav Tóth <jtoth@frinx.io>
restconf/restconf-nb-bierman02/src/main/java/org/opendaylight/netconf/sal/restconf/impl/ControllerContext.java
restconf/restconf-nb-bierman02/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/URITest.java
restconf/restconf-nb-bierman02/src/test/resources/full-versions/yangs/simple-nodes.yang

index 1db92eb10c1797458dee75f84080dfdc6febeec5..39a61379eb4daaa4a139c18afd317172e6fedb09 100644 (file)
@@ -562,6 +562,12 @@ public final class ControllerContext implements SchemaContextListener, Closeable
         }
 
         final String head = strings.iterator().next();
+
+        if (head.isEmpty()) {
+            final List<String> remaining = strings.subList(1, strings.size());
+            return collectPathArguments(builder, remaining, parentNode, mountPoint, returnJustMountPoint);
+        }
+
         final String nodeName = toNodeName(head);
         final String moduleName = toModuleName(head);
 
index 2b989063d3553b4a5d9c7b482e10ddb3cafb918a..5e1d59d7c70f481195caaacf0374a214bd5f8892 100644 (file)
@@ -64,6 +64,21 @@ public class URITest {
 
     }
 
+    @Test
+    public void testToInstanceIdentifierWithDoubleSlash() {
+        InstanceIdentifierContext<?> instanceIdentifier = controllerContext
+                .toInstanceIdentifier("simple-nodes:food//nonalcoholic");
+        assertEquals(instanceIdentifier.getSchemaNode().getQName().getLocalName(), "nonalcoholic");
+
+        instanceIdentifier = controllerContext
+                .toInstanceIdentifier("simple-nodes:userWithoutClass//");
+        assertEquals(instanceIdentifier.getSchemaNode().getQName().getLocalName(), "userWithoutClass");
+
+        instanceIdentifier = controllerContext
+                .toInstanceIdentifier("simple-nodes:userWithoutClass///inner-container");
+        assertEquals(instanceIdentifier.getSchemaNode().getQName().getLocalName(), "inner-container");
+    }
+
     @Test
     public void testToInstanceIdentifierListWithNullKey() {
         this.exception.expect(RestconfDocumentedException.class);
index 0dec051ac7380a5aa92235e4ca9deb9ca0168c9b..6c1625455e6a1e9cbfdd20658ade382fb5bb9620 100644 (file)
@@ -43,6 +43,11 @@ module simple-nodes {
         leaf full-name {
             type string;
         }
+        container inner-container {
+            leaf inner-list {
+                type uint16;
+            }
+        }
     }
     
      container food {