Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@
import org.springframework.web.util.pattern.PathPattern;
import org.springframework.web.util.pattern.PathPatternParser;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
* The type Path match utils.
*/
Expand All @@ -44,15 +41,15 @@ public class PathMatchUtils {
.build();

/**
* replace url {id} to real param.
* Replace literal URL placeholders with their actual values.
*
* @param path the total path
* @param regex the regex content
* @param target the literal text to replace
* @param replacement the replacement content
* @return the string
*/
public static String replaceAll(final String path, final String regex, final String replacement) {
return path.replaceAll(Pattern.quote(regex), Matcher.quoteReplacement(replacement));
public static String replaceAll(final String path, final String target, final String replacement) {
return path.replace(target, replacement);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ public void testPathVariableHandle() {
assertThat(realPath, is("demo/order/path/1/godfje@"));
}

@Test
public void testReplaceAllTreatsTargetAndReplacementAsLiterals() {
assertEquals("/$1\\value/$1\\value", PathMatchUtils.replaceAll("/{id.}/{id.}", "{id.}", "$1\\value"));
assertEquals("/{idx}", PathMatchUtils.replaceAll("/{idx}", "{id.}", "$1"));
}

private Cache<?, ?> getCache(final String fieldName) throws ReflectiveOperationException {
Field cacheField = PathMatchUtils.class.getDeclaredField(fieldName);
cacheField.setAccessible(true);
Expand Down
Loading