You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by gn...@apache.org on 2026/05/14 18:35:22 UTC

(maven) branch fix/condition-parser-arithmetic-delimiters created (now 0aeb2bdb78)

This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a change to branch fix/condition-parser-arithmetic-delimiters
in repository https://gitbox.apache.org/repos/asf/maven.git


      at 0aeb2bdb78 Fix #12052: tokenize arithmetic operators as delimiters in ConditionParser

This branch includes the following new commits:

     new 0aeb2bdb78 Fix #12052: tokenize arithmetic operators as delimiters in ConditionParser

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(maven) 01/01: Fix #12052: tokenize arithmetic operators as delimiters in ConditionParser

Posted by gn...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

gnodet pushed a commit to branch fix/condition-parser-arithmetic-delimiters
in repository https://gitbox.apache.org/repos/asf/maven.git

commit 0aeb2bdb783c0614bd4b3c1b988595aa9cf655b2
Author: Guillaume Nodet <gn...@gmail.com>
AuthorDate: Thu May 14 20:35:08 2026 +0200

    Fix #12052: tokenize arithmetic operators as delimiters in ConditionParser
    
    The tokenizer did not recognize `-`, `*`, `/` as delimiter characters,
    so expressions like `5-3` or `6*4` (without spaces) were tokenized as
    single tokens and failed to parse.
    
    Co-Authored-By: Claude Opus 4.6 (1M context) <no...@anthropic.com>
---
 .../org/apache/maven/impl/model/profile/ConditionParser.java |  4 ++--
 .../apache/maven/impl/model/profile/ConditionParserTest.java | 12 ++++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionParser.java b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionParser.java
index f596946aa2..b20d621c95 100644
--- a/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionParser.java
+++ b/impl/maven-impl/src/main/java/org/apache/maven/impl/model/profile/ConditionParser.java
@@ -129,8 +129,8 @@ 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 == '(' || c == ')' || c == ',' || c == '+' || c == '-' || c == '*' || c == '/'
+                    || c == '>' || c == '<' || c == '=' || c == '!') {
                 if (!sb.isEmpty()) {
                     tokens.add(sb.toString());
                     sb.setLength(0);
diff --git a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/ConditionParserTest.java b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/ConditionParserTest.java
index 56d2cbb3ae..7dd9559f86 100644
--- a/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/ConditionParserTest.java
+++ b/impl/maven-impl/src/test/java/org/apache/maven/impl/model/profile/ConditionParserTest.java
@@ -242,6 +242,18 @@ void testArithmeticFunctions() {
         assertEquals(2.5, parser.parse("5 / 2"));
     }
 
+    @Test
+    void testArithmeticWithoutSpaces() {
+        assertEquals(5.0, parser.parse("2+3"));
+        assertEquals(10.0, parser.parse("15-5"));
+        assertEquals(24.0, parser.parse("6*4"));
+        assertEquals(3.0, parser.parse("9/3"));
+        assertEquals(14.0, parser.parse("2+3*4"));
+        assertEquals(20.0, parser.parse("(2+3)*4"));
+        assertEquals(-5.0, parser.parse("-5"));
+        assertEquals(-5.0, parser.parse("-(2+3)"));
+    }
+
     @Test
     void testCombinedArithmeticAndLogic() {
         assertTrue((Boolean) parser.parse("(5 > 3) && (10 / 2 == 5)"));