Commit 15d6662c authored by Matt Benson's avatar Matt Benson Committed by Phillip Webb

Fix SpringProfileDocumentMatcher negation bug

Prior to this commit SpringProfileDocumentMatcher was returning 'found'
anytime a negated profile was not found, even if there were positive
profile matches required and unsatisfied.

Closes gh-5747
See gh-4953
parent 56146f0e
...@@ -68,10 +68,10 @@ public class SpringProfileDocumentMatcher implements DocumentMatcher { ...@@ -68,10 +68,10 @@ public class SpringProfileDocumentMatcher implements DocumentMatcher {
if (StringUtils.hasLength(negative)) { if (StringUtils.hasLength(negative)) {
properties = new Properties(properties); properties = new Properties(properties);
properties.setProperty(SPRING_PROFILES, negative); properties.setProperty(SPRING_PROFILES, negative);
switch (activeProfilesMatcher.matches(properties)) { if (activeProfilesMatcher.matches(properties) == MatchStatus.FOUND) {
case FOUND:
return MatchStatus.NOT_FOUND; return MatchStatus.NOT_FOUND;
case NOT_FOUND: }
if (StringUtils.isEmpty(positive)) {
return MatchStatus.FOUND; return MatchStatus.FOUND;
} }
properties.setProperty(SPRING_PROFILES, positive); properties.setProperty(SPRING_PROFILES, positive);
......
...@@ -85,12 +85,19 @@ public class SpringProfileDocumentMatcherTests { ...@@ -85,12 +85,19 @@ public class SpringProfileDocumentMatcherTests {
} }
@Test @Test
public void negatedAndNonNegated() throws IOException { public void negatedWithMatch() throws Exception {
DocumentMatcher matcher = new SpringProfileDocumentMatcher("foo", "bar", "blah"); DocumentMatcher matcher = new SpringProfileDocumentMatcher("foo", "bar", "blah");
Properties properties = getProperties("spring.profiles: !baz,blah"); Properties properties = getProperties("spring.profiles: !baz,blah");
assertThat(matcher.matches(properties)).isEqualTo(MatchStatus.FOUND); assertThat(matcher.matches(properties)).isEqualTo(MatchStatus.FOUND);
} }
@Test
public void negatedWithNoMatch() throws IOException {
DocumentMatcher matcher = new SpringProfileDocumentMatcher("foo", "bar", "blah");
Properties properties = getProperties("spring.profiles: !baz,another");
assertThat(matcher.matches(properties)).isEqualTo(MatchStatus.NOT_FOUND);
}
@Test @Test
public void negatedTrumpsMatching() throws IOException { public void negatedTrumpsMatching() throws IOException {
DocumentMatcher matcher = new SpringProfileDocumentMatcher("foo", "baz", "blah"); DocumentMatcher matcher = new SpringProfileDocumentMatcher("foo", "baz", "blah");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment