diff --git a/common/src/main/java/org/keycloak/common/util/PathMatcher.java b/common/src/main/java/org/keycloak/common/util/PathMatcher.java index 302c2553cc..d7c609f7f4 100644 --- a/common/src/main/java/org/keycloak/common/util/PathMatcher.java +++ b/common/src/main/java/org/keycloak/common/util/PathMatcher.java @@ -202,7 +202,9 @@ public abstract class PathMatcher

{ } } - i = expectedUri.indexOf('}', i); + if (c == '{') { + i = expectedUri.indexOf('}', i); + } if (i == expectedUri.lastIndexOf('}') && onlyFirstParam) { return String.valueOf(matchingUri).substring(0, matchingUriLastIndex); diff --git a/common/src/test/java/org/keycloak/common/util/PathMatcherTest.java b/common/src/test/java/org/keycloak/common/util/PathMatcherTest.java new file mode 100644 index 0000000000..2af7c68ffe --- /dev/null +++ b/common/src/test/java/org/keycloak/common/util/PathMatcherTest.java @@ -0,0 +1,34 @@ +package org.keycloak.common.util; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.Collection; + +public class PathMatcherTest { + + @Test + public void keycloak15833Test() { + TestingPathMatcher matcher = new TestingPathMatcher(); + + Assert.assertNull(matcher.customBuildUriFromTemplate("/api/v1/{clientId}/campaigns/*/excelFiles", "/api/v1/1/contentConnectorConfigs/29/contentConnectorContents", false)); + } + + private static final class TestingPathMatcher extends PathMatcher { + + @Override + protected String getPath(Object entry) { + return null; + } + + @Override + protected Collection getPaths() { + return null; + } + + // Make buildUriFromTemplate accessible from test + public String customBuildUriFromTemplate(String template, String targetUri, boolean onlyFirstParam) { + return buildUriFromTemplate(template, targetUri, onlyFirstParam); + } + } +}