Skip to content

Commit 9138dbc

Browse files
committed
Remove unnecessary escapes in regular expressions
Update copy right year Remove unnecessary escaping Remove unnecessary escaping in AbstractHttpSendingTransportHandler class Remove unnecessary escaping in ClassPathResourceTests Remove unnecessary escaping in CustomizableTraceInterceptor Remove unnecessary escaping in MessageBrokerBeanDefinitionParserTests Remove unnecessary escaping in RedirectView Remove unnecessary escaping in RegexPathElement Remove unnecessary escaping in TestContextResourceUtils Remove unnecessary escaping in UriComponents Remove unnecessary escaping in UriComponentsBuilder Remove unnecessary escaping in WebSocketMessageBrokerConfigurationSupportTests
1 parent 8dfacbc commit 9138dbc

File tree

11 files changed

+24
-24
lines changed

11 files changed

+24
-24
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public class CustomizableTraceInterceptor extends AbstractTraceInterceptor {
147147
/**
148148
* The {@code Pattern} used to match placeholders.
149149
*/
150-
private static final Pattern PATTERN = Pattern.compile("\\$\\[\\p{Alpha}+\\]");
150+
private static final Pattern PATTERN = Pattern.compile("\\$\\[\\p{Alpha}+]");
151151

152152
/**
153153
* The {@code Set} of allowed placeholders.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2020 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -77,7 +77,7 @@ public class AntPathMatcher implements PathMatcher {
7777

7878
private static final int CACHE_TURNOFF_THRESHOLD = 65536;
7979

80-
private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\{[^/]+?\\}");
80+
private static final Pattern VARIABLE_PATTERN = Pattern.compile("\\{[^/]+?}");
8181

8282
private static final char[] WILDCARD_CHARS = { '*', '?', '{' };
8383

@@ -641,7 +641,7 @@ public Comparator<String> getPatternComparator(String path) {
641641
*/
642642
protected static class AntPathStringMatcher {
643643

644-
private static final Pattern GLOB_PATTERN = Pattern.compile("\\?|\\*|\\{((?:\\{[^/]+?\\}|[^/{}]|\\\\[{}])+?)\\}");
644+
private static final Pattern GLOB_PATTERN = Pattern.compile("\\?|\\*|\\{((?:\\{[^/]+?}|[^/{}]|\\\\[{}])+?)}");
645645

646646
private static final String DEFAULT_VARIABLE_PATTERN = "(.*)";
647647

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ class ClassPathResourceTests {
4343
*/
4444
private static final String FQ_RESOURCE_PATH_WITH_LEADING_SLASH = '/' + FQ_RESOURCE_PATH;
4545

46-
private static final Pattern DESCRIPTION_PATTERN = Pattern.compile("^class path resource \\[(.+?)\\]$");
46+
private static final Pattern DESCRIPTION_PATTERN = Pattern.compile("^class path resource \\[(.+?)]$");
4747

4848

4949
@Test

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public abstract class TestContextResourceUtils {
4747

4848
private static final String SLASH = "/";
4949

50-
private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile(".*\\$\\{[^\\}]+\\}.*");
50+
private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile(".*\\$\\{[^}]+}.*");
5151

5252

5353
/**

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
public abstract class UriComponents implements Serializable {
4949

5050
/** Captures URI template variable names. */
51-
private static final Pattern NAMES_PATTERN = Pattern.compile("\\{([^/]+?)\\}");
51+
private static final Pattern NAMES_PATTERN = Pattern.compile("\\{([^/]+?)}");
5252

5353

5454
@Nullable

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
7676

7777
private static final String HOST_IPV4_PATTERN = "[^\\[/?#:]*";
7878

79-
private static final String HOST_IPV6_PATTERN = "\\[[\\p{XDigit}\\:\\.]*[%\\p{Alnum}]*\\]";
79+
private static final String HOST_IPV6_PATTERN = "\\[[\\p{XDigit}:.]*[%\\p{Alnum}]*]";
8080

8181
private static final String HOST_PATTERN = "(" + HOST_IPV6_PATTERN + "|" + HOST_IPV4_PATTERN + ")";
8282

83-
private static final String PORT_PATTERN = "(\\d*(?:\\{[^/]+?\\})?)";
83+
private static final String PORT_PATTERN = "(\\d*(?:\\{[^/]+?})?)";
8484

8585
private static final String PATH_PATTERN = "([^?#]*)";
8686

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
*/
3636
class RegexPathElement extends PathElement {
3737

38-
private static final Pattern GLOB_PATTERN = Pattern.compile("\\?|\\*|\\{((?:\\{[^/]+?\\}|[^/{}]|\\\\[{}])+?)\\}");
38+
private static final Pattern GLOB_PATTERN = Pattern.compile("\\?|\\*|\\{((?:\\{[^/]+?}|[^/{}]|\\\\[{}])+?)}");
3939

4040
private static final String DEFAULT_VARIABLE_PATTERN = "(.*)";
4141

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
*/
5454
public class RedirectView extends AbstractUrlBasedView {
5555

56-
private static final Pattern URI_TEMPLATE_VARIABLE_PATTERN = Pattern.compile("\\{([^/]+?)\\}");
56+
private static final Pattern URI_TEMPLATE_VARIABLE_PATTERN = Pattern.compile("\\{([^/]+?)}");
5757

5858

5959
private HttpStatus statusCode = HttpStatus.SEE_OTHER;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public abstract class AbstractHttpSendingTransportHandler extends AbstractTransp
4848
/**
4949
* Pattern for validating callback parameter values.
5050
*/
51-
private static final Pattern CALLBACK_PARAM_PATTERN = Pattern.compile("[0-9A-Za-z_\\.]*");
51+
private static final Pattern CALLBACK_PARAM_PATTERN = Pattern.compile("[0-9A-Za-z_.]*");
5252

5353

5454
@Override

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,16 +303,16 @@ public void stompBrokerRelay() {
303303
WebSocketMessageBrokerStats stats = this.appContext.getBean(name, WebSocketMessageBrokerStats.class);
304304
String actual = stats.toString();
305305
String expected = "WebSocketSession\\[0 current WS\\(0\\)-HttpStream\\(0\\)-HttpPoll\\(0\\), " +
306-
"0 total, 0 closed abnormally \\(0 connect failure, 0 send limit, 0 transport error\\)\\], " +
307-
"stompSubProtocol\\[processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)\\], " +
306+
"0 total, 0 closed abnormally \\(0 connect failure, 0 send limit, 0 transport error\\)], " +
307+
"stompSubProtocol\\[processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)], " +
308308
"stompBrokerRelay\\[0 sessions, relayhost:1234 \\(not available\\), " +
309-
"processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)\\], " +
309+
"processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)], " +
310310
"inboundChannel\\[pool size = \\d, active threads = \\d, queued tasks = \\d, " +
311-
"completed tasks = \\d\\], " +
311+
"completed tasks = \\d], " +
312312
"outboundChannel\\[pool size = \\d, active threads = \\d, queued tasks = \\d, " +
313-
"completed tasks = \\d\\], " +
313+
"completed tasks = \\d], " +
314314
"sockJsScheduler\\[pool size = \\d, active threads = \\d, queued tasks = \\d, " +
315-
"completed tasks = \\d\\]";
315+
"completed tasks = \\d]";
316316

317317
assertThat(actual.matches(expected)).as("\nExpected: " + expected.replace("\\", "") + "\n Actual: " + actual).isTrue();
318318
}

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,12 +168,12 @@ public void webSocketMessageBrokerStats() {
168168
WebSocketMessageBrokerStats stats = config.getBean(name, WebSocketMessageBrokerStats.class);
169169
String actual = stats.toString();
170170
String expected = "WebSocketSession\\[0 current WS\\(0\\)-HttpStream\\(0\\)-HttpPoll\\(0\\), " +
171-
"0 total, 0 closed abnormally \\(0 connect failure, 0 send limit, 0 transport error\\)\\], " +
172-
"stompSubProtocol\\[processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)\\], " +
173-
"stompBrokerRelay\\[null\\], " +
174-
"inboundChannel\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\], " +
175-
"outboundChannel\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\], " +
176-
"sockJsScheduler\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d\\]";
171+
"0 total, 0 closed abnormally \\(0 connect failure, 0 send limit, 0 transport error\\)], " +
172+
"stompSubProtocol\\[processed CONNECT\\(0\\)-CONNECTED\\(0\\)-DISCONNECT\\(0\\)], " +
173+
"stompBrokerRelay\\[null], " +
174+
"inboundChannel\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d], " +
175+
"outboundChannel\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d], " +
176+
"sockJsScheduler\\[pool size = \\d, active threads = \\d, queued tasks = \\d, completed tasks = \\d]";
177177

178178
assertThat(actual.matches(expected)).as("\nExpected: " + expected.replace("\\", "") + "\n Actual: " + actual).isTrue();
179179
}

0 commit comments

Comments
 (0)