Skip to content

Commit bbc34a6

Browse files
committed
Polish "Handle possible regexes defensively in NamePatternFilter"
Closes gh-9730
1 parent c29d1c7 commit bbc34a6

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/NamePatternFilter.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 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.
@@ -46,8 +46,8 @@ abstract class NamePatternFilter<T> {
4646
}
4747

4848
public Map<String, Object> getResults(String name) {
49-
Pattern pattern = getRegexPattern(name);
50-
if (pattern == null) { // this is not a regex
49+
Pattern pattern = compilePatternIfNecessary(name);
50+
if (pattern == null) {
5151
Object value = getValue(this.source, name);
5252
Map<String, Object> result = new HashMap<String, Object>();
5353
result.put(name, value);
@@ -60,13 +60,13 @@ public Map<String, Object> getResults(String name) {
6060

6161
}
6262

63-
private Pattern getRegexPattern(String name) {
63+
private Pattern compilePatternIfNecessary(String name) {
6464
for (String part : REGEX_PARTS) {
6565
if (name.contains(part)) {
6666
try {
6767
return Pattern.compile(name);
6868
}
69-
catch (PatternSyntaxException e) {
69+
catch (PatternSyntaxException ex) {
7070
return null;
7171
}
7272
}

spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/NamePatternFilterTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 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.

0 commit comments

Comments
 (0)