Skip to content

Commit 9dc1597

Browse files
committed
[gh-11363] Fix pipe symbol parsing in .mvn/jvm.config
The concat_lines function in the Unix mvn script was using xargs -n 1 which split arguments by whitespace, causing pipe symbols (|) in JVM arguments to be interpreted as shell command separators. This fix replaces the problematic implementation with a line-by-line reader that preserves quoted arguments and special characters while maintaining all existing functionality: - Comments are still removed - Empty lines are still filtered out - Variable substitution (MAVEN_PROJECTBASEDIR) still works - Pipe symbols and other special characters are preserved The Windows mvn.cmd script was already handling this correctly and does not require changes. Added integration test to verify pipe symbols in jvm.config work correctly and don't cause shell parsing errors.
1 parent 39bd4b7 commit 9dc1597

File tree

4 files changed

+126
-13
lines changed

4 files changed

+126
-13
lines changed

apache-maven/src/assembly/maven/bin/mvn

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -168,21 +168,19 @@ find_file_argument_basedir() {
168168
# concatenates all lines of a file and replaces variables
169169
concat_lines() {
170170
if [ -f "$1" ]; then
171-
# First convert all CR to LF using tr
171+
# Read file line by line, remove comments and empty lines, then perform variable substitution
172+
# This preserves quoted arguments and doesn't split on whitespace within quotes
172173
tr '\r' '\n' < "$1" | \
173174
sed -e '/^$/d' -e 's/#.*$//' | \
174-
# Replace LF with NUL for xargs
175-
tr '\n' '\0' | \
176-
# Split into words and process each argument
177-
# Use -0 with NUL to avoid special behaviour on quotes
178-
xargs -n 1 -0 | \
179-
while read -r arg; do
180-
# Replace variables first
181-
arg=$(echo "$arg" | sed \
182-
-e "s@\${MAVEN_PROJECTBASEDIR}@$MAVEN_PROJECTBASEDIR@g" \
183-
-e "s@\$MAVEN_PROJECTBASEDIR@$MAVEN_PROJECTBASEDIR@g")
184-
185-
echo "$arg"
175+
while IFS= read -r line; do
176+
# Skip empty lines after comment removal
177+
if [ -n "$line" ]; then
178+
# Replace variables
179+
line=$(echo "$line" | sed \
180+
-e "s@\${MAVEN_PROJECTBASEDIR}@$MAVEN_PROJECTBASEDIR@g" \
181+
-e "s@\$MAVEN_PROJECTBASEDIR@$MAVEN_PROJECTBASEDIR@g")
182+
echo "$line"
183+
fi
186184
done | \
187185
tr '\n' ' '
188186
fi
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.it;
20+
21+
import java.nio.file.Path;
22+
import java.util.Properties;
23+
24+
import org.junit.jupiter.api.Test;
25+
26+
import static org.junit.jupiter.api.Assertions.assertEquals;
27+
28+
/**
29+
* This is a test set for <a href="https://issues.apache.org/jira/browse/MNG-11363">MNG-11363</a>:
30+
* Verify that pipe symbols in .mvn/jvm.config are properly handled and don't cause shell command parsing errors.
31+
*/
32+
public class MavenITmng11363PipeSymbolsInJvmConfigTest extends AbstractMavenIntegrationTestCase {
33+
34+
/**
35+
* Verify that pipe symbols in .mvn/jvm.config are properly handled
36+
*/
37+
@Test
38+
void testPipeSymbolsInJvmConfig() throws Exception {
39+
Path basedir = extractResources("/mng-11363-pipe-symbols-jvm-config")
40+
.getAbsoluteFile()
41+
.toPath();
42+
43+
Verifier verifier = newVerifier(basedir.toString());
44+
verifier.setForkJvm(true); // Use forked JVM to test .mvn/jvm.config processing
45+
verifier.addCliArguments("validate");
46+
verifier.execute();
47+
verifier.verifyErrorFreeLog();
48+
49+
Properties props = verifier.loadProperties("target/pom.properties");
50+
assertEquals("de|*.de|my.company.mirror.de", props.getProperty("project.properties.pom.prop.nonProxyHosts"));
51+
assertEquals("value|with|pipes", props.getProperty("project.properties.pom.prop.with.pipes"));
52+
}
53+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Test for MNG-11363: Maven 4 fails to parse pipe symbols in .mvn/jvm.config
2+
-Dhttp.nonProxyHosts=de|*.de|my.company.mirror.de
3+
-Dprop.with.pipes="value|with|pipes"
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
Licensed to the Apache Software Foundation (ASF) under one
4+
or more contributor license agreements. See the NOTICE file
5+
distributed with this work for additional information
6+
regarding copyright ownership. The ASF licenses this file
7+
to you under the Apache License, Version 2.0 (the
8+
"License"); you may not use this file except in compliance
9+
with the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing,
14+
software distributed under the License is distributed on an
15+
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
KIND, either express or implied. See the License for the
17+
specific language governing permissions and limitations
18+
under the License.
19+
-->
20+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
23+
<groupId>org.apache.maven.its.mng11363</groupId>
24+
<artifactId>test</artifactId>
25+
<version>1.0</version>
26+
27+
<name>Maven Integration Test :: MNG-11363</name>
28+
<description>Verify that JVM args can contain pipe symbols in .mvn/jvm.config.</description>
29+
30+
<properties>
31+
<pom.prop.nonProxyHosts>${http.nonProxyHosts}</pom.prop.nonProxyHosts>
32+
<pom.prop.with.pipes>${prop.with.pipes}</pom.prop.with.pipes>
33+
</properties>
34+
35+
<build>
36+
<plugins>
37+
<plugin>
38+
<groupId>org.apache.maven.its.plugins</groupId>
39+
<artifactId>maven-it-plugin-expression</artifactId>
40+
<version>2.1-SNAPSHOT</version>
41+
<executions>
42+
<execution>
43+
<id>test</id>
44+
<goals>
45+
<goal>eval</goal>
46+
</goals>
47+
<phase>validate</phase>
48+
<configuration>
49+
<outputFile>target/pom.properties</outputFile>
50+
<expressions>
51+
<expression>project/properties</expression>
52+
</expressions>
53+
</configuration>
54+
</execution>
55+
</executions>
56+
</plugin>
57+
</plugins>
58+
</build>
59+
</project>

0 commit comments

Comments
 (0)