Skip to content

Commit f0aa4f4

Browse files
committed
Escape closing curly braces in regular expressions for Android support
PR spring-projectsgh-24470 introduced a regression for Android users by no longer escaping closing curly braces in regular expressions. This commit therefore partially reverts the changes made in 273812f for closing curly braces (`}`). Closes gh27467
1 parent f64f070 commit f0aa4f4

File tree

6 files changed

+11
-11
lines changed

6 files changed

+11
-11
lines changed

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-2020 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -78,7 +78,7 @@ public class AntPathMatcher implements PathMatcher {
7878

7979
private static final int CACHE_TURNOFF_THRESHOLD = 65536;
8080

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

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

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

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

647647
private static final String DEFAULT_VARIABLE_PATTERN = "((?s).*)";
648648

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

Lines changed: 2 additions & 2 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-2021 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.
@@ -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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public class UriComponentsBuilder implements UriBuilder, Cloneable {
8585

8686
private static final String HOST_PATTERN = "(" + HOST_IPV6_PATTERN + "|" + HOST_IPV4_PATTERN + ")";
8787

88-
private static final String PORT_PATTERN = "(\\{[^}]+}?|[^/?#]*)";
88+
private static final String PORT_PATTERN = "(\\{[^}]+\\}?|[^/?#]*)";
8989

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 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.
@@ -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;

0 commit comments

Comments
 (0)