Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,10 @@ private static Profiles parseTokens(String expression, StringTokenizer tokens, C
}
case "!" -> elements.add(not(parseTokens(expression, tokens, Context.NEGATE)));
case ")" -> {
Profiles merged = merge(expression, elements, operator);
if (context == Context.PARENTHESIS) {
return merged;
return merge(expression, elements, operator);
}
elements.clear();
elements.add(merged);
operator = null;
assertWellFormed(expression, false);
}
default -> {
Profiles value = equals(token);
Expand All @@ -105,6 +102,7 @@ private static Profiles parseTokens(String expression, StringTokenizer tokens, C
}
}
}
assertWellFormed(expression, context != Context.PARENTHESIS);
return merge(expression, elements, operator);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ void ofAndExpression() {

@Test
void ofAndExpressionWithoutSpaces() {
Profiles profiles = Profiles.of("spring&framework)");
Profiles profiles = Profiles.of("(spring&framework)");
assertAndExpression(profiles);
}

Expand Down Expand Up @@ -292,6 +292,15 @@ void malformedExpressions() {
assertMalformed(() -> Profiles.of("a & b | c"));
}

@Test
void malformedExpressionsWithUnbalancedParentheses() {
assertMalformed(() -> Profiles.of("dev)"));
assertMalformed(() -> Profiles.of("(dev"));
assertMalformed(() -> Profiles.of("spring&framework)"));
assertMalformed(() -> Profiles.of("((dev)"));
assertMalformed(() -> Profiles.of("(dev))"));
}

@Test
void sensibleToString() {
assertThat(Profiles.of("spring")).hasToString("spring");
Expand Down