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


##########
impl/maven-support/src/main/java/org/apache/maven/settings/v4/ArgumentTokenizer.java:
##########
@@ -59,28 +58,34 @@ public static List<String> tokenize(String input) {
         StringBuilder current = new StringBuilder();
         boolean inDoubleQuotes = false;
         boolean inSingleQuotes = false;
+        boolean tokenStarted = false;
 
         for (int i = 0; i < input.length(); i++) {
             char c = input.charAt(i);
 
             if (c == '\\' && !inSingleQuotes && i + 1 < input.length()) {
                 // Backslash escape: outside single-quotes, \X is always a 
literal X.
                 current.append(input.charAt(++i));
+                tokenStarted = true;
             } else if (c == '"' && !inSingleQuotes) {
                 inDoubleQuotes = !inDoubleQuotes;
+                tokenStarted = true;
             } else if (c == '\'' && !inDoubleQuotes) {
                 inSingleQuotes = !inSingleQuotes;
+                tokenStarted = true;
             } else if (Character.isWhitespace(c) && !inDoubleQuotes && 
!inSingleQuotes) {
-                if (current.length() > 0) {
+                if (tokenStarted) {
                     args.add(current.toString());
                     current.setLength(0);
+                    tokenStarted = false;
                 }
             } else {
                 current.append(c);
+                tokenStarted = true;

Review Comment:
   The `Note` paragraph now correctly drops the "identical algorithm" claim, 
but since `ArgumentTokenizer` now diverges from `JvmConfigParser` (this class 
preserves quoted empty args; `JvmConfigParser` does not), consider adding a 
sentence that makes the divergence explicit:
   
   > _Unlike `JvmConfigParser`, this implementation preserves quoted empty 
strings as empty arguments (e.g. `""` → `[""]` rather than `[]`)._



##########
impl/maven-support/src/test/java/org/apache/maven/settings/v4/SettingsStaxReaderTest.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.settings.v4;
+
+import java.io.StringReader;
+import java.io.StringWriter;
+import java.util.List;
+
+import org.apache.maven.api.settings.Settings;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+class SettingsStaxReaderTest {
+
+    @Test
+    void optionsPreserveQuotedEmptyArgument() throws Exception {
+        Settings settings = parse("<options>--log-file \"\" verify</options>");
+        assertEquals(List.of("--log-file", "", "verify"), settings.getArgs());
+    }
+
+    @Test
+    void aliasPreservesQuotedEmptyArgument() throws Exception {
+        Settings settings = parse("<alias name=\"ci\">--log-file '' 
verify</alias>");
+        assertEquals(
+                List.of("--log-file", "", "verify"),
+                settings.getAliases().get(0).getArgs());
+    }
+
+    @Test
+    void inlineAndStructuredEmptyArgumentsAreEquivalent() throws Exception {
+        Settings inline =
+                parse("<options>--log-file \"\" verify</options>" + "<alias 
name=\"ci\">--log-file '' verify</alias>");
+        Settings structured = 
parse("<options><arg>--log-file</arg><arg/><arg>verify</arg></options>"
+                + "<alias 
name=\"ci\"><arg>--log-file</arg><arg/><arg>verify</arg></alias>");
+
+        assertEquals(structured.getArgs(), inline.getArgs());
+        assertEquals(
+                structured.getAliases().get(0).getArgs(),

Review Comment:
   This line exceeds the project's 120-character limit. Consider splitting:
   
   ```java
   Settings inline = parse(
           "<options>--log-file \"\" verify</options>"
           + "<alias name=\"ci\">--log-file '' verify</alias>");
   ```



##########
impl/maven-support/src/test/java/org/apache/maven/settings/v4/ArgumentTokenizerTest.java:
##########
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.maven.settings.v4;
+
+import java.util.List;
+
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+
+class ArgumentTokenizerTest {
+
+    @Test
+    void doubleQuotedEmptyArgument() {
+        assertEquals(List.of("first", "", "third"), 
ArgumentTokenizer.tokenize("first \"\" third"));
+    }
+
+    @Test
+    void singleQuotedEmptyArgument() {
+        assertEquals(List.of("first", "", "third"), 
ArgumentTokenizer.tokenize("first '' third"));
+    }
+
+    @Test
+    void emptyArgumentsAtBoundaries() {
+        assertEquals(List.of(""), ArgumentTokenizer.tokenize("\"\""));
+        assertEquals(List.of(""), ArgumentTokenizer.tokenize("''"));
+        assertEquals(List.of("", "middle", ""), ArgumentTokenizer.tokenize("  
\"\" middle ''  "));
+    }
+
+    @Test
+    void consecutiveEmptyArguments() {
+        assertEquals(List.of("", "", ""), 
ArgumentTokenizer.tokenize("\"\"\t''\n\"\""));
+        assertEquals(List.of(""), ArgumentTokenizer.tokenize("\"\"''"));
+    }
+
+    @Test
+    void adjacentQuotedFragmentsStayInOneArgument() {
+        assertEquals(List.of("first", "third"), 
ArgumentTokenizer.tokenize("fi\"\"rst ''third"));

Review Comment:
   The second assertion (`"\"\"''"` → `[""]`) might surprise readers: adjacent 
quote pairs with no whitespace between them are part of the **same token**, not 
two separate empty arguments. A quick comment would make the intent clear:
   
   ```java
   // adjacent empty quotes without whitespace — merged into a single 
empty-string token
   assertEquals(List.of(""), ArgumentTokenizer.tokenize("\"\"''"));
   ```



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