Skip to content

Commit bdc5130

Browse files
committed
[gh-11363] Add pipe symbol escaping for Windows batch file
Windows command processor interprets pipe symbols as command separators, causing JVM arguments with pipes to fail. This commit adds: 1. A call to escapePipes subroutine in the JVM config processing 2. An escapePipes subroutine that escapes unquoted pipe symbols with ^^^| 3. Quote-aware processing to only escape pipes outside of quotes This ensures that JVM config files work correctly on Windows, macOS, and Linux with proper pipe symbol handling across all platforms.
1 parent e244f01 commit bdc5130

File tree

1 file changed

+39
-0
lines changed
  • apache-maven/src/assembly/maven/bin

1 file changed

+39
-0
lines changed

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,9 @@ for /F "usebackq tokens=* delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.conf
199199
set "trimmed=!trimmed:${MAVEN_PROJECTBASEDIR}=%MAVEN_PROJECTBASEDIR%!"
200200
set "trimmed=!trimmed:$MAVEN_PROJECTBASEDIR=%MAVEN_PROJECTBASEDIR%!"
201201

202+
rem Escape pipe symbols that are not within quotes to prevent command separation
203+
call :escapePipes "!trimmed!" trimmed
204+
202205
if not "!trimmed!"=="" (
203206
if "!JVM_CONFIG_MAVEN_OPTS!"=="" (
204207
set "JVM_CONFIG_MAVEN_OPTS=!trimmed!"
@@ -287,3 +290,39 @@ if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd"
287290
if "%MAVEN_BATCH_PAUSE%"=="on" pause
288291

289292
exit /b %ERROR_CODE%
293+
294+
rem Subroutine to escape pipe symbols that are not within quotes
295+
:escapePipes
296+
setlocal EnableDelayedExpansion
297+
set "input=%~1"
298+
set "output="
299+
set "inQuotes=0"
300+
set "i=0"
301+
302+
:escapeLoop
303+
set "char=!input:~%i%,1!"
304+
if "!char!"=="" goto escapeEnd
305+
306+
if "!char!"=="^"" (
307+
if "!inQuotes!"=="0" (
308+
set "inQuotes=1"
309+
) else (
310+
set "inQuotes=0"
311+
)
312+
set "output=!output!!char!"
313+
) else if "!char!"=="|" (
314+
if "!inQuotes!"=="0" (
315+
set "output=!output!^^^|"
316+
) else (
317+
set "output=!output!!char!"
318+
)
319+
) else (
320+
set "output=!output!!char!"
321+
)
322+
323+
set /a "i+=1"
324+
goto escapeLoop
325+
326+
:escapeEnd
327+
endlocal & set "%~2=%output%"
328+
goto :eof

0 commit comments

Comments
 (0)