From 9058cc75d99116ddcc8ff5ac8df29de5608e36b3 Mon Sep 17 00:00:00 2001 From: Michal Hajas Date: Wed, 21 Oct 2020 16:39:12 +0200 Subject: [PATCH] KEYCLOAK-15833 Look for end bracket only if current block is pattern --- .../org/keycloak/common/util/PathMatcher.java | 4 ++- .../keycloak/common/util/PathMatcherTest.java | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 common/src/test/java/org/keycloak/common/util/PathMatcherTest.java 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); + } + } +}