Skip to content

[2.x] fix: Handle paths with parentheses in sbt.bat on Windows#8656

Merged
eed3si9n merged 5 commits intosbt:developfrom
Eruis2579:fix-8644-windows-parentheses-in-path
Jan 29, 2026
Merged

[2.x] fix: Handle paths with parentheses in sbt.bat on Windows#8656
eed3si9n merged 5 commits intosbt:developfrom
Eruis2579:fix-8644-windows-parentheses-in-path

Conversation

@Eruis2579
Copy link
Copy Markdown
Contributor

@Eruis2579 Eruis2579 commented Jan 29, 2026

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

  • Added set "CURRENT_DIR=%CD%" to store the current directory in a variable
  • Changed "%CD%" to "!CURRENT_DIR!" in the error message to use delayed expansion
  • Added test script test-parentheses-path.bat to verify the fix works correctly

Testing

A test script has been added (launcher-package/citest/test-parentheses-path.bat) that:

  1. Creates a test directory with parentheses in the name
  2. Runs sbt.bat from that directory
  3. Verifies error messages display correctly without parsing errors

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

@Eruis2579 Eruis2579 changed the title Fix sbt.bat to handle paths with parentheses (fixes #8644) Fix #8644: Handle paths with parentheses in sbt.bat on Windows Jan 29, 2026
@Eruis2579 Eruis2579 changed the title Fix #8644: Handle paths with parentheses in sbt.bat on Windows Fix : Handle paths with parentheses in sbt.bat on Windows Jan 29, 2026
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
@Eruis2579 Eruis2579 force-pushed the fix-8644-windows-parentheses-in-path branch from c146708 to e4a2fbe Compare January 29, 2026 15:36
@eed3si9n
Copy link
Copy Markdown
Member

Hi @Eruis2579, thanks for the contribution!

Please follow https://github.com/sbt/sbt/blob/develop/CONTRIBUTING.md and:

  1. include tests for the change
  2. read our Gen-AI assisted contributions guideline (please declare usage in the PR description, if you used it)
  3. sign Scala CLA https://contribute.akka.io/contribute/cla/scala

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.
@Eruis2579 Eruis2579 changed the title Fix : Handle paths with parentheses in sbt.bat on Windows Fix #8644: Handle paths with parentheses in sbt.bat on Windows Jan 29, 2026
@Eruis2579
Copy link
Copy Markdown
Contributor Author

Hi @Eruis2579, thanks for the contribution!

Please follow https://github.com/sbt/sbt/blob/develop/CONTRIBUTING.md and:

  1. include tests for the change
  2. read our Gen-AI assisted contributions guideline (please declare usage in the PR description, if you used it)
  3. sign Scala CLA https://contribute.akka.io/contribute/cla/scala

Hi, @eed3si9n , Thank you for your review
I have added tests for the change and signed Scala CLA.
Please check again.

@eed3si9n
Copy link
Copy Markdown
Member

Could you write the test using Scala if possible? Here's an example -

test("sbt in empty directory") {
IO.withTemporaryDirectory { tmp =>
val out = sbtProcessInDir(tmp)("about").!
assert(out == 1)
}
IO.withTemporaryDirectory { tmp =>
val out = sbtProcessInDir(tmp)("about", "--allow-empty").!
assert(out == 0)
}
()
}

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
@Eruis2579 Eruis2579 force-pushed the fix-8644-windows-parentheses-in-path branch from db3efda to c9a751c Compare January 29, 2026 17:30
@Eruis2579
Copy link
Copy Markdown
Contributor Author

Hi, @eed3si9n
I added the test using Scala. Please test it.
Thanks for your review.

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.
Copy link
Copy Markdown
Member

@eed3si9n eed3si9n left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.
@Eruis2579
Copy link
Copy Markdown
Contributor Author

Hi, @eed3si9n
Can you merge my PR?
thank you.

@eed3si9n eed3si9n changed the title Fix #8644: Handle paths with parentheses in sbt.bat on Windows [2.x] fix: Handle paths with parentheses in sbt.bat on Windows Jan 29, 2026
@eed3si9n eed3si9n merged commit 461e12d into sbt:develop Jan 29, 2026
15 checks passed
@eed3si9n
Copy link
Copy Markdown
Member

eed3si9n commented Jan 29, 2026

@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

eed3si9n pushed a commit to eed3si9n/sbt that referenced this pull request Feb 3, 2026
)

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
eed3si9n added a commit that referenced this pull request Feb 3, 2026
#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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows: sbt.bat fails when project path contains parentheses

2 participants