Skip to content

Remove redundant escapes in regular expressions #24470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
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 @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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 = { '*', '?', '{' };

Expand Down Expand Up @@ -641,7 +641,7 @@ public Comparator<String> getPatternComparator(String path) {
*/
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 = "(.*)";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(".*\\$\\{[^}]+}.*");


/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "([^?#]*)";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
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 = "(.*)";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
*/
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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,16 +303,16 @@ public void stompBrokerRelay() {
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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ public void webSocketMessageBrokerStats() {
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();
}
Expand Down