Skip to content

Commit 44027a1

Browse files
committed
Fix Windows batch file syntax error in escapePipes subroutine
The original code used 'if "\!char\!"=="^""' to check for double quote characters, but this syntax doesn't work correctly with delayed expansion enabled in Windows batch files, causing "The syntax of the command is incorrect" errors. The fix introduces an intermediate variable 'isQuote' and uses the proper batch file syntax 'if "\!char\!"==""""' (four consecutive quotes) to check for a double quote character. This is the standard way to represent a literal quote in batch file comparisons. This resolves the IT failures on Windows for tests that use jvm.config files, including: - MavenITmng8598JvmConfigSubstitutionTest - MavenITmng6255FixConcatLines - MavenITmng6223FindBasedir
1 parent d1dc6f1 commit 44027a1

File tree

1 file changed

+42
-1
lines changed
  • apache-maven/src/assembly/maven/bin

1 file changed

+42
-1
lines changed

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

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,4 +263,45 @@ if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd"
263263
@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on'
264264
if "%MAVEN_BATCH_PAUSE%"=="on" pause
265265

266-
exit /b %ERROR_CODE%
266+
exit /b %ERROR_CODE%
267+
268+
rem Subroutine to escape pipe symbols that are not within quotes
269+
:escapePipes
270+
setlocal EnableDelayedExpansion
271+
set "input=%~1"
272+
set "output="
273+
set "inQuotes=0"
274+
set "i=0"
275+
276+
:escapeLoop
277+
set "char=!input:~%i%,1!"
278+
if "!char!"=="" goto escapeEnd
279+
280+
rem Check if character is a double quote using string comparison
281+
set "isQuote=0"
282+
if "!char!"=="""" set "isQuote=1"
283+
284+
if "!isQuote!"=="1" (
285+
if "!inQuotes!"=="0" (
286+
set "inQuotes=1"
287+
) else (
288+
set "inQuotes=0"
289+
)
290+
set "output=!output!!char!"
291+
) else if "!char!"=="|" (
292+
if "!inQuotes!"=="0" (
293+
rem Escape pipe with 7 carets to survive endlocal and command line parsing
294+
set "output=!output!^^^^^^^|"
295+
) else (
296+
set "output=!output!!char!"
297+
)
298+
) else (
299+
set "output=!output!!char!"
300+
)
301+
302+
set /a "i+=1"
303+
goto escapeLoop
304+
305+
:escapeEnd
306+
endlocal & set "%~2=%output%"
307+
goto :eof

0 commit comments

Comments
 (0)