From 548d7b3f325b01324c750ed2cb112bd7fe7b8d4d Mon Sep 17 00:00:00 2001 From: dbego Date: Tue, 11 Jul 2017 11:05:12 -0400 Subject: [PATCH 1/2] * Replace isRegex by getRegexPattern that checks if a possible regex can be compiled * Code Format * Catch PatternSyntaxException instead of RuntimeException * Fix Checkstyle violations Revert "* Catch PatternSyntaxException instead of RuntimeException" This reverts commit 0b85e4f6d99e1072827d57893a32aa6615fdeced. * Ctach PatternSyntaxException instead of RuntimeException * Fix checkstyle violations * Delete flag parameter --- .../actuate/endpoint/mvc/NamePatternFilter.java | 17 ++++++++++++----- .../endpoint/mvc/NamePatternFilterTests.java | 8 ++++++++ 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/NamePatternFilter.java b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/NamePatternFilter.java index d3ed23610c50..87d48e8d2db4 100644 --- a/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/NamePatternFilter.java +++ b/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/endpoint/mvc/NamePatternFilter.java @@ -20,6 +20,7 @@ import java.util.LinkedHashMap; import java.util.Map; import java.util.regex.Pattern; +import java.util.regex.PatternSyntaxException; /** * Utility class that can be used to filter source data using a name regular expression. @@ -31,6 +32,7 @@ * @author Phillip Webb * @author Sergei Egorov * @author Andy Wilkinson + * @author Dylian Bego * @since 1.3.0 */ abstract class NamePatternFilter { @@ -44,13 +46,13 @@ abstract class NamePatternFilter { } public Map getResults(String name) { - if (!isRegex(name)) { + Pattern pattern = getRegexPattern(name); + if (pattern == null) { // this is not a regex Object value = getValue(this.source, name); Map result = new HashMap<>(); result.put(name, value); return result; } - Pattern pattern = Pattern.compile(name); ResultCollectingNameCallback resultCollector = new ResultCollectingNameCallback( pattern); getNames(this.source, resultCollector); @@ -58,13 +60,18 @@ public Map getResults(String name) { } - private boolean isRegex(String name) { + private Pattern getRegexPattern(String name) { for (String part : REGEX_PARTS) { if (name.contains(part)) { - return true; + try { + return Pattern.compile(name); + } + catch (PatternSyntaxException e) { + return null; + } } } - return false; + return null; } protected abstract void getNames(T source, NameCallback callback); diff --git a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/NamePatternFilterTests.java b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/NamePatternFilterTests.java index 1cdee1829806..3ed021000d50 100644 --- a/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/NamePatternFilterTests.java +++ b/spring-boot-actuator/src/test/java/org/springframework/boot/actuate/endpoint/mvc/NamePatternFilterTests.java @@ -27,6 +27,7 @@ * * @author Phillip Webb * @author Andy Wilkinson + * @author Dylian Bego */ public class NamePatternFilterTests { @@ -38,6 +39,13 @@ public void nonRegex() throws Exception { assertThat(filter.isGetNamesCalled()).isFalse(); } + @Test + public void nonRegexThatContainsRegexPart() throws Exception { + MockNamePatternFilter filter = new MockNamePatternFilter(); + assertThat(filter.getResults("*")).containsEntry("*", "*"); + assertThat(filter.isGetNamesCalled()).isFalse(); + } + @Test public void regexRepetitionZeroOrMore() { MockNamePatternFilter filter = new MockNamePatternFilter(); From 88dca246e6d8ede13535dab3e8a69ba619e0116e Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Sun, 9 Jul 2017 14:43:32 +0200 Subject: [PATCH 2/2] Fix source repository links in maven plugin site Closes gh-9671 --- spring-boot-tools/spring-boot-maven-plugin/pom.xml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/spring-boot-tools/spring-boot-maven-plugin/pom.xml b/spring-boot-tools/spring-boot-maven-plugin/pom.xml index 79a5a1eb032a..653fd8c2c568 100644 --- a/spring-boot-tools/spring-boot-maven-plugin/pom.xml +++ b/spring-boot-tools/spring-boot-maven-plugin/pom.xml @@ -112,9 +112,13 @@ + + https://github.com/spring-projects/spring-boot/ + scm:git:git://github.com/spring-projects/spring-boot.git + scm:git:ssh://git@github.com/spring-projects/spring-boot.git + -