Skip to content

Commit cee2209

Browse files
aschemanclaude
andcommitted
Fix mvn script expanding ${...} in CLI arguments
The eval in the mvn script causes shell expansion of ${...} patterns in user-provided arguments. Pass user arguments directly via "$@" instead of concatenating them into the eval string. This preserves MAVEN_OPTS word splitting while preventing unintended shell expansion. Fixes #11978 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 388337b commit cee2209

1 file changed

Lines changed: 6 additions & 8 deletions

File tree

  • apache-maven/src/assembly/maven/bin

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ handle_args() {
275275
handle_args "$@"
276276
MAVEN_MAIN_CLASS=${MAVEN_MAIN_CLASS:=org.apache.maven.cling.MavenCling}
277277

278-
# Build command string for eval
278+
# Build base command string for eval (only contains Maven-controlled values)
279279
cmd="\"$JAVACMD\" \
280280
$MAVEN_OPTS \
281281
$MAVEN_DEBUG_OPTS \
@@ -289,14 +289,12 @@ cmd="\"$JAVACMD\" \
289289
$LAUNCHER_CLASS \
290290
$MAVEN_ARGS"
291291

292-
# Add remaining arguments with proper quoting
293-
for arg in "$@"; do
294-
cmd="$cmd \"$arg\""
295-
done
296-
297292
if [ -n "$MAVEN_DEBUG_SCRIPT" ]; then
298293
echo "[DEBUG] Launching JVM with command:" >&2
299-
echo "[DEBUG] $cmd" >&2
294+
echo "[DEBUG] $cmd" "$@" >&2
300295
fi
301296

302-
eval exec "$cmd"
297+
# User arguments ("$@") are passed directly to preserve literal values
298+
# like ${...} Maven property placeholders without shell expansion.
299+
# Only the base command uses eval for MAVEN_OPTS word splitting.
300+
eval exec "$cmd" '"$@"'

0 commit comments

Comments
 (0)