gnodet commented on code in PR #12038:
URL: https://github.com/apache/maven/pull/12038#discussion_r3243423286


##########
impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/ConditionParserTest.java:
##########
@@ -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.
+
+        // 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 -> {

Review Comment:
   Please also add a test for `||` with newlines, similar to 
`testAmpersandAmpersandTokenizerMultiline`. For example:
   
   ```java
   @Test
   void testPipePipeTokenizerMultiline() {
       // || with newlines should work the same as &&
       assertTrue((Boolean) parser.parse("${os.arch} == 'amd64' || ${os.name} 
== 'linux'"));
       assertTrue((Boolean) parser.parse("${os.arch} == 'amd64'\n|| ${os.name} 
== 'linux'"));
       assertTrue((Boolean) parser.parse("${os.arch} == 'amd64' ||\n${os.name} 
== 'linux'"));
       assertTrue((Boolean) parser.parse("${os.arch} == 'amd64'\n||\n${os.name} 
== 'linux'"));
   }
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to