Skip to content

Commit 7779aa3

Browse files
committed
Polish contribution
See gh-23297
1 parent 84200f3 commit 7779aa3

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ private void deactivatePatternCache() {
169169

170170
@Override
171171
public boolean isPattern(String path) {
172-
if(path == null) {
172+
if (path == null) {
173173
return false;
174174
}
175175
boolean uriVar = false;
@@ -202,15 +202,15 @@ public boolean matchStart(String pattern, String path) {
202202
/**
203203
* Actually match the given {@code path} against the given {@code pattern}.
204204
* @param pattern the pattern to match against
205-
* @param path the path String to test
205+
* @param path the path to test
206206
* @param fullMatch whether a full pattern match is required (else a pattern match
207207
* as far as the given base path goes is sufficient)
208208
* @return {@code true} if the supplied {@code path} matched, {@code false} if it didn't
209209
*/
210210
protected boolean doMatch(String pattern, String path, boolean fullMatch,
211211
@Nullable Map<String, String> uriTemplateVariables) {
212212

213-
if (path == null || path.startsWith(this.pathSeparator) != pattern.startsWith(this.pathSeparator)) {
213+
if ((path == null) || (path.startsWith(this.pathSeparator) != pattern.startsWith(this.pathSeparator))) {
214214
return false;
215215
}
216216

@@ -418,7 +418,7 @@ protected String[] tokenizePattern(String pattern) {
418418
}
419419

420420
/**
421-
* Tokenize the given path String into parts, based on this matcher's settings.
421+
* Tokenize the given path into parts, based on this matcher's settings.
422422
* @param path the path to tokenize
423423
* @return the tokenized path parts
424424
*/

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2019 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.
@@ -41,7 +41,7 @@ public interface PathMatcher {
4141
* <p>If the return value is {@code false}, then the {@link #match}
4242
* method does not have to be used because direct equality comparisons
4343
* on the static path Strings will lead to the same result.
44-
* @param path the path String to check
44+
* @param path the path to check
4545
* @return {@code true} if the given {@code path} represents a pattern
4646
*/
4747
boolean isPattern(String path);
@@ -50,7 +50,7 @@ public interface PathMatcher {
5050
* Match the given {@code path} against the given {@code pattern},
5151
* according to this PathMatcher's matching strategy.
5252
* @param pattern the pattern to match against
53-
* @param path the path String to test
53+
* @param path the path to test
5454
* @return {@code true} if the supplied {@code path} matched,
5555
* {@code false} if it didn't
5656
*/
@@ -62,7 +62,7 @@ public interface PathMatcher {
6262
* <p>Determines whether the pattern at least matches as far as the given base
6363
* path goes, assuming that a full path may then match as well.
6464
* @param pattern the pattern to match against
65-
* @param path the path String to test
65+
* @param path the path to test
6666
* @return {@code true} if the supplied {@code path} matched,
6767
* {@code false} if it didn't
6868
*/

spring-core/src/test/java/org/springframework/util/AntPathMatcherTests.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,10 @@ public void match() {
130130
assertThat(pathMatcher.match("", "")).isTrue();
131131

132132
assertThat(pathMatcher.match("/{bla}.*", "/testing.html")).isTrue();
133+
}
133134

135+
@Test
136+
public void matchWithNullPath() {
134137
assertThat(pathMatcher.match("/test", null)).isFalse();
135138
assertThat(pathMatcher.match("/", null)).isFalse();
136139
assertThat(pathMatcher.match("/", null)).isFalse();
@@ -146,7 +149,7 @@ public void matchWithTrimTokensEnabled() throws Exception {
146149
}
147150

148151
@Test
149-
public void withMatchStart() {
152+
public void matchStart() {
150153
// test exact matching
151154
assertThat(pathMatcher.matchStart("test", "test")).isTrue();
152155
assertThat(pathMatcher.matchStart("/test", "/test")).isTrue();
@@ -691,8 +694,13 @@ public void isPattern() {
691694
assertThat(pathMatcher.isPattern("/test/**/name")).isTrue();
692695
assertThat(pathMatcher.isPattern("/test?")).isTrue();
693696
assertThat(pathMatcher.isPattern("/test/{name}")).isTrue();
697+
694698
assertThat(pathMatcher.isPattern("/test/name")).isFalse();
695699
assertThat(pathMatcher.isPattern("/test/foo{bar")).isFalse();
700+
}
701+
702+
@Test // gh-23297
703+
public void isPatternWithNullPath() {
696704
assertThat(pathMatcher.isPattern(null)).isFalse();
697705
}
698706

0 commit comments

Comments
 (0)