KEYCLOAK-15833 Look for end bracket only if current block is pattern

This commit is contained in:
Michal Hajas 2020-10-21 16:39:12 +02:00 committed by Hynek Mlnařík
parent 267f1797d4
commit 9058cc75d9
2 changed files with 37 additions and 1 deletions

View file

@ -202,7 +202,9 @@ public abstract class PathMatcher<P> {
} }
} }
i = expectedUri.indexOf('}', i); if (c == '{') {
i = expectedUri.indexOf('}', i);
}
if (i == expectedUri.lastIndexOf('}') && onlyFirstParam) { if (i == expectedUri.lastIndexOf('}') && onlyFirstParam) {
return String.valueOf(matchingUri).substring(0, matchingUriLastIndex); return String.valueOf(matchingUri).substring(0, matchingUriLastIndex);

View file

@ -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<Object> {
@Override
protected String getPath(Object entry) {
return null;
}
@Override
protected Collection<Object> getPaths() {
return null;
}
// Make buildUriFromTemplate accessible from test
public String customBuildUriFromTemplate(String template, String targetUri, boolean onlyFirstParam) {
return buildUriFromTemplate(template, targetUri, onlyFirstParam);
}
}
}