Browse Source

Remove unnecessary escapes in regular expressions

See gh-24470
pull/24476/head
Hyunjin Choi 6 years ago committed by Rossen Stoyanchev
parent
commit
273812f9c5
  1. 2
      spring-aop/src/main/java/org/springframework/aop/interceptor/CustomizableTraceInterceptor.java
  2. 6
      spring-core/src/main/java/org/springframework/util/AntPathMatcher.java
  3. 2
      spring-core/src/test/java/org/springframework/core/io/ClassPathResourceTests.java
  4. 2
      spring-test/src/main/java/org/springframework/test/context/util/TestContextResourceUtils.java
  5. 2
      spring-web/src/main/java/org/springframework/web/util/UriComponents.java
  6. 4
      spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java
  7. 2
      spring-web/src/main/java/org/springframework/web/util/pattern/RegexPathElement.java
  8. 2
      spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RedirectView.java
  9. 2
      spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpSendingTransportHandler.java
  10. 12
      spring-websocket/src/test/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParserTests.java
  11. 12
      spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupportTests.java

2
spring-aop/src/main/java/org/springframework/aop/interceptor/CustomizableTraceInterceptor.java

@ -147,7 +147,7 @@ public class CustomizableTraceInterceptor extends AbstractTraceInterceptor { @@ -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.

6
spring-core/src/main/java/org/springframework/util/AntPathMatcher.java

@ -1,5 +1,5 @@ @@ -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 { @@ -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 { @@ -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 = "(.*)";

2
spring-core/src/test/java/org/springframework/core/io/ClassPathResourceTests.java

@ -43,7 +43,7 @@ class ClassPathResourceTests { @@ -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

2
spring-test/src/main/java/org/springframework/test/context/util/TestContextResourceUtils.java

@ -47,7 +47,7 @@ public abstract class TestContextResourceUtils { @@ -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(".*\\$\\{[^}]+}.*");
/**

2
spring-web/src/main/java/org/springframework/web/util/UriComponents.java

@ -48,7 +48,7 @@ import org.springframework.util.MultiValueMap; @@ -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

4
spring-web/src/main/java/org/springframework/web/util/UriComponentsBuilder.java

@ -76,11 +76,11 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable { @@ -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 = "([^?#]*)";

2
spring-web/src/main/java/org/springframework/web/util/pattern/RegexPathElement.java

@ -35,7 +35,7 @@ import org.springframework.web.util.pattern.PathPattern.MatchingContext; @@ -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 = "(.*)";

2
spring-webflux/src/main/java/org/springframework/web/reactive/result/view/RedirectView.java

@ -53,7 +53,7 @@ import org.springframework.web.util.UriUtils; @@ -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;

2
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/AbstractHttpSendingTransportHandler.java

@ -48,7 +48,7 @@ public abstract class AbstractHttpSendingTransportHandler extends AbstractTransp @@ -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

12
spring-websocket/src/test/java/org/springframework/web/socket/config/MessageBrokerBeanDefinitionParserTests.java

@ -303,16 +303,16 @@ public class MessageBrokerBeanDefinitionParserTests { @@ -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();
}

12
spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupportTests.java

@ -168,12 +168,12 @@ public class WebSocketMessageBrokerConfigurationSupportTests { @@ -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();
}

Loading…
Cancel
Save