[2.x] fix: Handle paths with parentheses in sbt.bat on Windows#8656
[2.x] fix: Handle paths with parentheses in sbt.bat on Windows#8656eed3si9n merged 5 commits intosbt:developfrom
Conversation
Windows CMD interprets parentheses as special syntax for command grouping. When the project directory path contains parentheses (e.g., in username), the batch script fails with ') was unexpected at this time.' error. This fix stores the current directory in a variable using delayed expansion (!CURRENT_DIR!) instead of using %CD% directly, which properly handles paths containing parentheses and other special characters. Fixes sbt#8644
c146708 to
e4a2fbe
Compare
|
Hi @Eruis2579, thanks for the contribution! Please follow https://github.com/sbt/sbt/blob/develop/CONTRIBUTING.md and:
|
This test verifies the fix for issue sbt#8644 by: 1. Creating a test directory with parentheses in the name 2. Running sbt.bat from that directory 3. Verifying error messages display correctly without parsing errors The test ensures that paths containing parentheses are properly handled using delayed expansion in the batch script.
Hi, @eed3si9n , Thank you for your review |
|
Could you write the test using Scala if possible? Here's an example - sbt/launcher-package/integration-test/src/test/scala/ExtendedRunnerTest.scala Lines 105 to 115 in f05a96a |
Replace the batch file test with a proper Scala integration test following the existing test patterns in ExtendedRunnerTest.scala. The test verifies that sbt.bat correctly handles paths containing parentheses by: 1. Creating a temporary directory with parentheses in the name 2. Running sbt from that directory and verifying it works 3. Testing error messages display correctly without parsing errors This addresses the reviewer's request to use Scala tests instead of batch file tests. Fixes sbt#8644
db3efda to
c9a751c
Compare
|
Hi, @eed3si9n |
Use ProcessLogger to capture stderr when sbt exits with non-zero code, instead of using !! which throws an exception on failure. This allows the test to verify that error messages don't contain parsing errors when paths have parentheses.
launcher-package/integration-test/src/test/scala/ExtendedRunnerTest.scala
Outdated
Show resolved
Hide resolved
eed3si9n
left a comment
There was a problem hiding this comment.
Overall looking good! Thanks!
Refactor test to use IO.withTemporaryDirectory loan pattern instead of manually creating and deleting the directory. This ensures automatic cleanup even if an exception is thrown during test execution.
|
Hi, @eed3si9n |
|
@Eruis2579 Landed. Would you like to double dip on this by cherry picking the commit on against 1.12.x branch? I've created an issue #8658 |
) Windows CMD interprets parentheses as special syntax for command grouping. When the project directory path contains parentheses (e.g., in username), the batch script fails with ') was unexpected at this time.' error. This fix stores the current directory in a variable using delayed expansion (!CURRENT_DIR!) instead of using %CD% directly, which properly handles paths containing parentheses and other special characters. Fixes sbt#8644
#8682) Windows CMD interprets parentheses as special syntax for command grouping. When the project directory path contains parentheses (e.g., in username), the batch script fails with ') was unexpected at this time.' error. This fix stores the current directory in a variable using delayed expansion (!CURRENT_DIR!) instead of using %CD% directly, which properly handles paths containing parentheses and other special characters. Fixes #8644
Problem
Windows CMD interprets parentheses as special syntax for command grouping. When the project directory path contains parentheses (e.g., in username like
C:\\Users\\Anshuman(work)\\Desktop\\myproject), the batch script fails with) was unexpected at this time.error.Solution
This fix stores the current directory in a variable using delayed expansion (
!CURRENT_DIR!) instead of using%CD%directly, which properly handles paths containing parentheses and other special characters.Changes
set "CURRENT_DIR=%CD%"to store the current directory in a variable"%CD%"to"!CURRENT_DIR!"in the error message to use delayed expansiontest-parentheses-path.batto verify the fix works correctlyTesting
A test script has been added (
launcher-package/citest/test-parentheses-path.bat) that:This fix ensures that paths with parentheses are properly handled when displayed in error messages. The delayed expansion mechanism in Windows batch files correctly processes special characters.
Fixes #8644