kwin commented on code in PR #2229: URL: https://github.com/apache/jackrabbit-oak/pull/2229#discussion_r2062641247
########## oak-jcr/src/test/java/org/apache/jackrabbit/oak/jcr/session/JackrabbitSessionTest.java: ########## @@ -86,20 +88,39 @@ public void testGetExpandedName() throws RepositoryException { assertEquals("{}testroot", s.getExpandedName(testRootNode)); Node n = testRootNode.addNode("test:bar"); assertEquals("{http://www.apache.org/jackrabbit/test}bar", s.getExpandedName(n)); - // now remap namespace uri + // now remap namespace uri - should not affect expanded name + assertEquals("prefix 'test' has unexpected mapping", + "http://www.apache.org/jackrabbit/test", s.getNamespaceURI("test")); s.setNamespacePrefix("test", "urn:foo"); - assertEquals("{urn:foo}bar", s.getExpandedName(n)); + assertEquals("{http://www.apache.org/jackrabbit/test}bar", s.getExpandedName(n)); // use special namespace uri n = testRootNode.addNode("rep:bar"); assertEquals("{internal}bar", s.getExpandedName(n)); } + public void testGetExpandedNameBrokenNamespace() throws RepositoryException { + // empty namespace uri + assertEquals("{}testroot", s.getExpandedName(testRootNode)); + + // register broken namespace name + s.getWorkspace().getNamespaceRegistry().registerNamespace("foo", "bar"); Review Comment: shouldn't this fail? ########## oak-core/src/main/java/org/apache/jackrabbit/oak/namepath/impl/GlobalNameMapper.java: ########## @@ -143,17 +146,23 @@ public String getExpandedJcrName(@NotNull String oakName) { int colon = oakName.indexOf(':'); if (colon > 0) { String oakPrefix = oakName.substring(0, colon); - // local mapping must take precedence... - uri = getSessionLocalMappings().get(oakPrefix); + uri = getNamespacesProperty(oakPrefix); + // global mapping must take precedence... if (uri == null) { - // ...over global mappings - uri = getNamespacesProperty(oakPrefix); + // ...over local mappings + uri = getSessionLocalMappings().get(oakPrefix); } if (uri == null) { throw new IllegalStateException( "No namespace mapping found for " + oakName); } localName = oakName.substring(colon + 1); + // check namespace name for validity in Oak + if (!isValidNamespaceName(uri)) { + throw new IllegalStateException( + new NamespaceException("Cannot determine expanded name for '" + oakName + Review Comment: how can one register an invalid namespace in oak in the first place? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: oak-dev-unsubscr...@jackrabbit.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org