Skip to content

Commit

Permalink
Fix SpringProfileDocumentMatcher negation bug
Browse files Browse the repository at this point in the history
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 spring-projectsgh-5747
See spring-projectsgh-4953
  • Loading branch information
mbenson authored and philwebb committed Apr 25, 2016
1 parent 56146f0 commit 15d6662
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ public MatchStatus matches(Properties properties) {
if (StringUtils.hasLength(negative)) {
properties = new Properties(properties);
properties.setProperty(SPRING_PROFILES, negative);
switch (activeProfilesMatcher.matches(properties)) {
case FOUND:
if (activeProfilesMatcher.matches(properties) == MatchStatus.FOUND) {
return MatchStatus.NOT_FOUND;
case NOT_FOUND:
}
if (StringUtils.isEmpty(positive)) {
return MatchStatus.FOUND;
}
properties.setProperty(SPRING_PROFILES, positive);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,19 @@ public void testInverseMatchMulti() throws IOException {
}

@Test
public void negatedAndNonNegated() throws IOException {
public void negatedWithMatch() throws Exception {
DocumentMatcher matcher = new SpringProfileDocumentMatcher("foo", "bar", "blah");
Properties properties = getProperties("spring.profiles: !baz,blah");
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
public void negatedTrumpsMatching() throws IOException {
DocumentMatcher matcher = new SpringProfileDocumentMatcher("foo", "baz", "blah");
Expand Down

0 comments on commit 15d6662

Please sign in to comment.