Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -129,18 +129,21 @@ private List<String> tokenize(String expression) {
}
quoteType = c;
sb.append(c);
} else if (c == ' ' || c == '(' || c == ')' || c == ',' || c == '+' || c == '>' || c == '<' || c == '='
|| c == '!') {
} else if (c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == '(' || c == ')' || c == ',' || c == '+'
|| c == '>' || c == '<' || c == '=' || c == '!' || c == '&') {
Comment thread
blaspat marked this conversation as resolved.
Outdated
if (!sb.isEmpty()) {
tokens.add(sb.toString());
sb.setLength(0);
}
if (c != ' ') {
if ((c == '>' || c == '<' || c == '=' || c == '!')
if (c != ' ' && c != '\n' && c != '\r' && c != '\t') {
Comment thread
blaspat marked this conversation as resolved.
Outdated
if ((c == '>' || c == '<' || c == '=' || c == '!' || c == '&')
&& i + 1 < expression.length()
&& expression.charAt(i + 1) == '=') {
tokens.add(c + "=");
i++; // Skip the next character
} else if (c == '&' && i + 1 < expression.length() && expression.charAt(i + 1) == '&') {
tokens.add("&&");
i++; // Skip the next character
Comment thread
blaspat marked this conversation as resolved.
Outdated
} else {
tokens.add(String.valueOf(c));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,32 @@ void testPropertyAlias() {
assertThrows(RuntimeException.class, () -> parser.parse("${unclosed"));
}

@Test
void testAmpersandAmpersandTokenizerMultiline() {
// Regression test for https://github.com/apache/maven/issues/11882
// The && operator was not being tokenized correctly when a line break appeared before it.
// Uses ${os.name} and ${os.arch} which work reliably in the test environment.
// ${os.name} == 'windows' && ${os.arch} == 'amd64' evaluates to true.
Comment thread
blaspat marked this conversation as resolved.
Outdated

// Case 1: Basic && without line breaks (baseline - always worked)
assertTrue((Boolean) parser.parse("${os.arch} == 'amd64' && ${os.name} == 'windows'"));

// Case 2: Line break BEFORE && - this was the bug from issue #11882
// In the issue, CDATA content had a line break before &&:
// <condition><![CDATA[exists( '.profile-2' )\n&& missing( '.profile-1' )]]></condition>
assertTrue((Boolean) parser.parse("${os.arch} == 'amd64'\n&& ${os.name} == 'windows'"));

// Case 3: Line break AFTER &&
assertTrue((Boolean) parser.parse("${os.arch} == 'amd64' &&\n${os.name} == 'windows'"));

// Case 4: Line breaks on both sides
assertTrue((Boolean) parser.parse("${os.arch} == 'amd64'\n&&\n${os.name} == 'windows'"));

// Case 5: Multiple && with line break before first && (like bad-profile-2d in issue)
assertTrue(
(Boolean) parser.parse("${os.arch} == 'amd64'\n&& ${os.name} == 'windows' && ${os.name} == 'windows'"));
}

@Test
void testNestedPropertyAlias() {
functions.put("property", args -> {
Comment thread
blaspat marked this conversation as resolved.
Expand Down
Loading