Remove unnecessary escapes in regular expressions

See gh-24470
This commit is contained in:
Hyunjin Choi 2020-02-03 21:30:25 +09:00 committed by Rossen Stoyanchev
parent cf9a052e3a
commit 273812f9c5
11 changed files with 24 additions and 24 deletions

View File

@ -147,7 +147,7 @@ public class CustomizableTraceInterceptor extends AbstractTraceInterceptor {
/**
* The {@code Pattern} used to match placeholders.
*/
private static final Pattern PATTERN = Pattern.compile("\\$\\[\\p{Alpha}+\\]");
private static final Pattern PATTERN = Pattern.compile("\\$\\[\\p{Alpha}+]");
/**
* The {@code Set} of allowed placeholders.

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2020 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -77,7 +77,7 @@ public class AntPathMatcher implements PathMatcher {
private static final int CACHE_TURNOFF_THRESHOLD = 65536;
private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\{[^/]+?\\}");
private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\{[^/]+?}");
private static final char[] WILDCARD_CHARS = { '*', '?', '{' };
@ -641,7 +641,7 @@ public class AntPathMatcher implements PathMatcher {
*/
protected static class AntPathStringMatcher {
private static final Pattern GLOB_PATTERN = Pattern.compile("\\?|\\*|\\{((?:\\{[^/]+?\\}|[^/{}]|\\\\[{}])+?)\\}");
private static final Pattern GLOB_PATTERN = Pattern.compile("\\?|\\*|\\{((?:\\{[^/]+?}|[^/{}]|\\\\[{}])+?)}");
private static final String DEFAULT_VARIABLE_PATTERN = "(.*)";

View File

@ -43,7 +43,7 @@ class ClassPathResourceTests {
*/
private static final String FQ_RESOURCE_PATH_WITH_LEADING_SLASH = '/' + FQ_RESOURCE_PATH;
private static final Pattern DESCRIPTION_PATTERN = Pattern.compile("^class path resource \\[(.+?)\\]$");
private static final Pattern DESCRIPTION_PATTERN = Pattern.compile("^class path resource \\[(.+?)]$");
@Test

View File

@ -47,7 +47,7 @@ public abstract class TestContextResourceUtils {
private static final String SLASH = "/";
private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile(".*\\$\\{[^\\}]+\\}.*");
private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile(".*\\$\\{[^}]+}.*");
/**

View File

@ -48,7 +48,7 @@ import org.springframework.util.MultiValueMap;
public abstract class UriComponents implements Serializable {
/** Captures URI template variable names. */
private static final Pattern NAMES_PATTERN = Pattern.compile("\\{([^/]+?)\\}");
private static final Pattern NAMES_PATTERN = Pattern.compile("\\{([^/]+?)}");
@Nullable

View File

@ -76,11 +76,11 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
private static final String HOST_IPV4_PATTERN = "[^\\[/?#:]*";
private static final String HOST_IPV6_PATTERN = "\\[[\\p{XDigit}\\:\\.]*[%\\p{Alnum}]*\\]";
private static final String HOST_IPV6_PATTERN = "\\[[\\p{XDigit}:.]*[%\\p{Alnum}]*]";
private static final String HOST_PATTERN = "(" + HOST_IPV6_PATTERN + "|" + HOST_IPV4_PATTERN + ")";
private static final String PORT_PATTERN = "(\\d*(?:\\{[^/]+?\\})?)";
private static final String PORT_PATTERN = "(\\d*(?:\\{[^/]+?})?)";
private static final String PATH_PATTERN = "([^?#]*)";

View File

@ -35,7 +35,7 @@ import org.springframework.web.util.pattern.PathPattern.MatchingContext;
*/
class RegexPathElement extends PathElement {
private static final Pattern GLOB_PATTERN = Pattern.compile("\\?|\\*|\\{((?:\\{[^/]+?\\}|[^/{}]|\\\\[{}])+?)\\}");
private static final Pattern GLOB_PATTERN = Pattern.compile("\\?|\\*|\\{((?:\\{[^/]+?}|[^/{}]|\\\\[{}])+?)}");
private static final String DEFAULT_VARIABLE_PATTERN = "(.*)";

View File

@ -53,7 +53,7 @@ import org.springframework.web.util.UriUtils;
*/
public class RedirectView extends AbstractUrlBasedView {
private static final Pattern URI_TEMPLATE_VARIABLE_PATTERN = Pattern.compile("\\{([^/]+?)\\}");
private static final Pattern URI_TEMPLATE_VARIABLE_PATTERN = Pattern.compile("\\{([^/]+?)}");
private HttpStatus statusCode = HttpStatus.SEE_OTHER;

View File

@ -48,7 +48,7 @@ public abstract class AbstractHttpSendingTransportHandler extends AbstractTransp
/**
* Pattern for validating callback parameter values.
*/
private static final Pattern CALLBACK_PARAM_PATTERN = Pattern.compile("[0-9A-Za-z_\\.]*");
private static final Pattern CALLBACK_PARAM_PATTERN = Pattern.compile("[0-9A-Za-z_.]*");
@Override

View File

@ -303,16 +303,16 @@ public class MessageBrokerBeanDefinitionParserTests {
WebSocketMessageBrokerStats stats = this.appContext.getBean(name, WebSocketMessageBrokerStats.class);
String actual = stats.toString();
String expected = "WebSocketSession\\[0 current WS\\(0\\)-HttpStream\\(0\\)-HttpPoll\\(0\\), " +
"0 total, 0 closed abnormally \\(0 connect failure, 0 send limit, 0 transport error\\)\\], " +
"stompSubProtocol\\[processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)\\], " +
"0 total, 0 closed abnormally \\(0 connect failure, 0 send limit, 0 transport error\\)], " +
"stompSubProtocol\\[processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)], " +
"stompBrokerRelay\\[0 sessions, relayhost:1234 \\(not available\\), " +
"processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)\\], " +
"processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)], " +
"inboundChannel\\[pool size = \\d, active threads = \\d, queued tasks = \\d, " +
"completed tasks = \\d\\], " +
"completed tasks = \\d], " +
"outboundChannel\\[pool size = \\d, active threads = \\d, queued tasks = \\d, " +
"completed tasks = \\d\\], " +
"completed tasks = \\d], " +
"sockJsScheduler\\[pool size = \\d, active threads = \\d, queued tasks = \\d, " +
"completed tasks = \\d\\]";
"completed tasks = \\d]";
assertThat(actual.matches(expected)).as("\nExpected: " + expected.replace("\\", "") + "\n Actual: " + actual).isTrue();
}

View File

@ -168,12 +168,12 @@ public class WebSocketMessageBrokerConfigurationSupportTests {
WebSocketMessageBrokerStats stats = config.getBean(name, WebSocketMessageBrokerStats.class);
String actual = stats.toString();
String expected = "WebSocketSession\\[0 current WS\\(0\\)-HttpStream\\(0\\)-HttpPoll\\(0\\), " +
"0 total, 0 closed abnormally \\(0 connect failure, 0 send limit, 0 transport error\\)\\], " +
"stompSubProtocol\\[processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)\\], " +
"stompBrokerRelay\\[null\\], " +
"inboundChannel\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\], " +
"outboundChannel\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\], " +
"sockJsScheduler\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\]";
"0 total, 0 closed abnormally \\(0 connect failure, 0 send limit, 0 transport error\\)], " +
"stompSubProtocol\\[processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)], " +
"stompBrokerRelay\\[null], " +
"inboundChannel\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d], " +
"outboundChannel\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d], " +
"sockJsScheduler\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d]";
assertThat(actual.matches(expected)).as("\nExpected: " + expected.replace("\\", "") + "\n Actual: " + actual).isTrue();
}