Skip to content

[BI] Fix support for Ballerina installation paths containing spaces#1551

Merged
kanushka merged 3 commits intowso2:release/bi-1.8.xfrom
NipunaRanasinghe:release/bi-1.8.x
Feb 25, 2026
Merged

[BI] Fix support for Ballerina installation paths containing spaces#1551
kanushka merged 3 commits intowso2:release/bi-1.8.xfrom
NipunaRanasinghe:release/bi-1.8.x

Conversation

@NipunaRanasinghe
Copy link
Contributor

@NipunaRanasinghe NipunaRanasinghe commented Feb 24, 2026

Purpose

Fixes wso2/product-ballerina-integrator#2550

Goals

Describe the solutions that this feature/fix will introduce to resolve the problems described above

Approach

Describe how you are implementing the solutions. Include an animated GIF or screenshot if the change affects the UI (email documentation@wso2.com to review all UI text). Include a link to a Markdown file or Google doc if the feature write-up is too long to paste here.

UI Component Development

Specify the reason if following are not followed.

  • Added reusable UI components to the ui-toolkit. Follow the intructions when adding the componenent.
  • Use ui-toolkit components wherever possible. Run npm run storybook from the root directory to view current components.
  • Matches with the native VSCode look and feel.

Manage Icons

Specify the reason if following are not followed.

  • Added Icons to the font-wso2-vscode. Follow the instructions.

User stories

Summary of user stories addressed by this change>

Release note

Brief description of the new feature or bug fix as it will appear in the release notes

Documentation

Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter “N/A” plus brief explanation of why there’s no doc impact

Training

Link to the PR for changes to the training content in https://github.com/wso2/WSO2-Training, if applicable

Certification

Type “Sent” when you have provided new/updated certification questions, plus four answers for each question (correct answer highlighted in bold), based on this change. Certification questions/answers should be sent to certification@wso2.com and NOT pasted in this PR. If there is no impact on certification exams, type “N/A” and explain why.

Marketing

Link to drafts of marketing content that will describe and promote this feature, including product page changes, technical articles, blog posts, videos, etc., if applicable

Automation tests

  • Unit tests

    Code coverage information

  • Integration tests

    Details about the test cases and coverage

Security checks

Samples

Provide high-level details about the samples related to this feature

Related PRs

List any other related PRs

Migrations (if applicable)

Describe migration steps and platforms on which migration has been tested

Test environment

List all JDK versions, operating systems, databases, and browser/versions on which this feature/fix was tested

Learning

Describe the research phase and any blog posts, patterns, libraries, or add-ons you used to solve the problem.

Summary by CodeRabbit

  • Bug Fixes
    • Improved handling and quoting of the Ballerina CLI path across initialization, debugging, test running, project commands, and migration tooling to better support paths with spaces and improve reliability on Windows, WSL, and Linux.

Copilot AI review requested due to automatic review settings February 24, 2026 17:49
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 24, 2026

📝 Walkthrough

Walkthrough

Adds a new quoteShellPath utility and applies it across the extension to quote executable paths when building shell command strings, updating command construction in the core extension, test runner, debugger, project runner, testing runner, and migration tool.

Changes

Cohort / File(s) Summary
Utility Function
workspaces/ballerina/ballerina-extension/src/utils/config.ts
Adds exported quoteShellPath(filePath: string) that strips surrounding quotes, escapes embedded quotes, and wraps paths containing spaces in double quotes.
Core Extension
workspaces/ballerina/ballerina-extension/src/core/extension.ts
Reworks bal executable handling to build balExecutablePath and use quoteShellPath(balExecutablePath) when constructing the version command; updates WSL/native-path logic to use the new variable.
AI / Test Runner
workspaces/ballerina/ballerina-extension/src/features/ai/agent/tools/test-runner.ts
Wraps Ballerina command with quoteShellPath when constructing test invocation command.
Debugger
workspaces/ballerina/ballerina-extension/src/features/debugger/config-provider.ts
Uses quoteShellPath for script/command path assembly in DebugAdapterDescriptorFactory and BIRunAdapter.run command construction.
Project Command Runner
workspaces/ballerina/ballerina-extension/src/features/project/cmds/cmd-runner.ts
Applies quoteShellPath to the executor when building command lines for RUN/OTHER flows to handle paths with spaces.
Testing Runner
workspaces/ballerina/ballerina-extension/src/features/testing/runner.ts
Wraps executor path with quoteShellPath when forming test commands.
Migration Integration
workspaces/ballerina/ballerina-extension/src/utils/migrate-integration.ts
Uses quoteShellPath for the Ballerina CLI path in the migration tool tool pull command construction.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 I hopped through paths both near and far,
And wrapped each space in a shining bar,
Now commands skip trips and no longer fall,
Quoted and safe — I`m proud, after all! 🥕✨

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Description check ⚠️ Warning The PR description is largely incomplete. Only the Purpose section is filled with a link to the issue, while critical sections like Goals, Approach, Release note, Documentation, Security checks, and Test environment remain unfilled with placeholder text. Complete the PR description by filling in the Goals section with the solution, the Approach section with implementation details, the Release note for users, Documentation/Testing information, and answers to all Security checks (yes/no responses required).
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: fixing support for Ballerina installation paths containing spaces. It directly aligns with the changeset modifications across multiple files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@workspaces/ballerina/ballerina-extension/src/utils/config.ts`:
- Around line 76-82: The quoteShellPath function currently double-quotes
already-quoted paths and does not escape embedded double-quotes; update
quoteShellPath to first normalize the input by trimming whitespace and removing
a single pair of surrounding quotes if present, then escape any internal
double-quote characters (e.g., replace " with \"), and finally wrap the
normalized/escaped path in a single pair of double quotes before returning;
ensure this logic is implemented inside the quoteShellPath function so existing
quoted inputs are not double-quoted and embedded quotes are escaped.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 825ce5c and a3477d8.

📒 Files selected for processing (7)
  • workspaces/ballerina/ballerina-extension/src/core/extension.ts
  • workspaces/ballerina/ballerina-extension/src/features/ai/agent/tools/test-runner.ts
  • workspaces/ballerina/ballerina-extension/src/features/debugger/config-provider.ts
  • workspaces/ballerina/ballerina-extension/src/features/project/cmds/cmd-runner.ts
  • workspaces/ballerina/ballerina-extension/src/features/testing/runner.ts
  • workspaces/ballerina/ballerina-extension/src/utils/config.ts
  • workspaces/ballerina/ballerina-extension/src/utils/migrate-integration.ts

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a bug where Ballerina installation paths containing spaces would cause command execution failures. The fix implements a utility function to quote shell paths when they contain spaces.

Changes:

  • Added quoteShellPath() utility function to wrap paths containing spaces in double quotes
  • Updated all Ballerina command execution points to use the new quoting function
  • Modified version detection logic to properly handle quoted paths

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
workspaces/ballerina/ballerina-extension/src/utils/config.ts Adds quoteShellPath() utility function to handle paths with spaces
workspaces/ballerina/ballerina-extension/src/utils/migrate-integration.ts Applies path quoting to migration tool pull command
workspaces/ballerina/ballerina-extension/src/features/testing/runner.ts Applies path quoting to test execution command
workspaces/ballerina/ballerina-extension/src/features/project/cmds/cmd-runner.ts Applies path quoting to project command execution
workspaces/ballerina/ballerina-extension/src/features/debugger/config-provider.ts Applies path quoting to debugger adapter and run commands
workspaces/ballerina/ballerina-extension/src/features/ai/agent/tools/test-runner.ts Applies path quoting to AI agent test runner command
workspaces/ballerina/ballerina-extension/src/core/extension.ts Refactors version detection to build executable path separately before quoting
Comments suppressed due to low confidence (1)

workspaces/ballerina/ballerina-extension/src/utils/config.ts:82

  • If the filePath already contains double quotes, this function will produce incorrectly nested quotes (e.g., \"path with \"quotes\" \") which will fail shell parsing. The function should either escape existing quotes or check for them before wrapping.
export function quoteShellPath(filePath: string): string {
    return filePath.includes(' ') ? `"${filePath}"` : filePath;
}

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

♻️ Duplicate comments (1)
workspaces/ballerina/ballerina-extension/src/utils/config.ts (1)

81-94: ⚠️ Potential issue | 🟠 Major

Handle single‑quoted and whitespace‑padded inputs in quoteShellPath.

Right now only double quotes are stripped and only literal spaces are checked. If users set 'C:\Program Files\bal.bat' (or have leading/trailing spaces), the function will wrap those quotes and the command will likely fail. Consider normalizing both quote styles, trimming, and checking any whitespace.

🛠️ Suggested fix
 export function quoteShellPath(filePath: string): string {
-    // Strip existing surrounding quotes to normalize
-    let normalized = filePath;
-    if (normalized.length >= 2 && normalized.startsWith('"') && normalized.endsWith('"')) {
-        normalized = normalized.slice(1, -1);
-    }
-
-    if (!normalized.includes(' ')) {
-        return normalized;
-    }
-
-    // Escape any embedded double quotes
-    const escaped = normalized.replace(/"/g, '\\"');
-    return `"${escaped}"`;
+    const trimmed = filePath.trim();
+    let normalized = trimmed;
+    if (
+        normalized.length >= 2 &&
+        ((normalized.startsWith('"') && normalized.endsWith('"')) ||
+            (normalized.startsWith("'") && normalized.endsWith("'")))
+    ) {
+        normalized = normalized.slice(1, -1);
+    }
+
+    const escaped = normalized.replace(/"/g, '\\"');
+    return /\s/.test(escaped) ? `"${escaped}"` : escaped;
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@workspaces/ballerina/ballerina-extension/src/utils/config.ts` around lines 81
- 94, The quoteShellPath function currently only strips surrounding double
quotes and checks for literal spaces, so inputs with single quotes or
leading/trailing whitespace slip through; update quoteShellPath to first trim()
the input, then detect and strip a single pair of surrounding quotes of either
type (single or double) into the normalized variable, then check for any
whitespace using a regex like /\s/ (not just ' ') and only if whitespace exists
escape embedded double quotes (escaped) and wrap with double quotes before
returning; reference quoteShellPath, normalized and escaped when making these
changes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Duplicate comments:
In `@workspaces/ballerina/ballerina-extension/src/utils/config.ts`:
- Around line 81-94: The quoteShellPath function currently only strips
surrounding double quotes and checks for literal spaces, so inputs with single
quotes or leading/trailing whitespace slip through; update quoteShellPath to
first trim() the input, then detect and strip a single pair of surrounding
quotes of either type (single or double) into the normalized variable, then
check for any whitespace using a regex like /\s/ (not just ' ') and only if
whitespace exists escape embedded double quotes (escaped) and wrap with double
quotes before returning; reference quoteShellPath, normalized and escaped when
making these changes.

ℹ️ Review info

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a3477d8 and 11d6560.

📒 Files selected for processing (1)
  • workspaces/ballerina/ballerina-extension/src/utils/config.ts

@kanushka kanushka merged commit a3a33f4 into wso2:release/bi-1.8.x Feb 25, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants