gnodet-bot commented on code in PR #14073:
URL: https://github.com/apache/maven/pull/14073#discussion_r4622532822


##########
impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/OperatingSystemProfileActivatorTest.java:
##########
@@ -70,6 +70,22 @@ void testVersionRegexMatching() throws Exception {
         assertActivation(false, profile, newContext(null, 
newProperties("linux", "3.1.0", "amd64")));
     }
 
+    @Test
+    void testVersionRegexKeepsCaseOfThePattern() throws Exception {
+        Profile profile = 
newProfile(ActivationOS.newBuilder().version("regex:\\S+-generic"));
+
+        assertActivation(true, profile, newContext(null, 
newProperties("linux", "6.5.0-41-generic", "amd64")));
+
+        assertActivation(false, profile, newContext(null, 
newProperties("linux", "6.5.0 41-generic", "amd64")));
+    }
+
+    @Test
+    void testVersionRegexMatchingIsCaseInsensitive() throws Exception {
+        Profile profile = 
newProfile(ActivationOS.newBuilder().version("regex:.*AWS"));
+
+        assertActivation(true, profile, newContext(null, 
newProperties("linux", "6.5.0-1014-aws", "amd64")));

Review Comment:
   **`testVersionRegexMatchingIsCaseInsensitive` doesn't actually validate 
`CASE_INSENSITIVE`.**
   
   With the old code, `expectedVersion.toLowerCase()` produces `regex:.*aws`; 
the pattern becomes `.*aws`. Since the actual version (`6.5.0-1014-aws`) 
already ends in lowercase `aws`, the match succeeds — this test passes 
identically **before and after the fix**.
   
   To truly exercise the new flag, the actual version needs an uppercase 
portion that only a case-insensitive match would catch, e.g.:
   
   ```java
   // pattern uppercase, actual mixed/upper — only matches because of 
CASE_INSENSITIVE
   assertActivation(true, profile, newContext(null, newProperties("linux", 
"6.5.0-1014-AWS", "amd64")));
   ```



##########
impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/OperatingSystemProfileActivator.java:
##########
@@ -105,7 +106,10 @@ private boolean determineVersionMatch(String 
expectedVersion, String actualVersi
         boolean reverse = false;
         final boolean result;
         if (test.startsWith(REGEX_PREFIX)) {
-            result = 
actualVersion.matches(test.substring(REGEX_PREFIX.length()));
+            // the pattern keeps its case: lower-casing it would turn \S into 
\s

Review Comment:
   **Comment explains only half the change.** The comment `// the pattern keeps 
its case: lower-casing it would turn \S into \s` explains why the pattern is no 
longer lowercased, but not why `Pattern.CASE_INSENSITIVE` is added. Worth 
completing it, e.g.:
   
   ```suggestion
               // keep the pattern's case to avoid \S→\s corruption; 
CASE_INSENSITIVE preserves the previous case-insensitive matching behaviour
   ```



-- 
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