8000 Fix: Properly handle paths with spaces in generated command by pkashin · Pull Request #749 · air-verse/air · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix: Properly handle paths with spaces in generated command #749

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2025

Conversation

pkashin
Copy link
Contributor
@pkashin pkashin commented Mar 3, 2025

Changes:

  1. Added formatPath() function in runner/util.go to:
    • Quote absolute paths with spaces.
    • Apply Windows-specific syntax when needed.
  2. Integrated formatPath() into command generation in runner/engine.go.
  3. Added comprehensive tests in runner/util_test.go covering:
    • Windows/Unix absolute/relative paths with/without spaces.
    • Edge cases (empty path, simple filename).

Testing:

  • Unit tests verify correct behavior across platforms.
  • Manually tested on [Windows 11/macOS 15] with paths containing spaces.

Notes:

  • This ensures commands like C:\Program Files\app.exe or /usr/local/my app/main execute correctly.

Closes #666

@pkashin pkashin changed the title Fix: Properly handle paths with spaces in generated command (#666) Fix: Properly handle paths with spaces in generated command #666 Mar 3, 2025
@pkashin pkashin changed the title Fix: Properly handle paths with spaces in generated command #666 Fix: Properly handle paths with spaces in generated command Mar 3, 2025
Copy link
codecov bot commented Mar 3, 2025

Codecov Report

Attention: Patch coverage is 75.00000% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
runner/util.go 70.00% 2 Missing and 1 partial ⚠️
Files with missing lines Coverage Δ
runner/engine.go 60.03% <100.00%> (+0.07%) ⬆️
runner/util.go 70.45% <70.00%> (-0.02%) ⬇️

@pkashin
Copy link
Contributor Author
pkashin commented Mar 3, 2025

Hi @xiantang,

I noticed that the Smoke test / smoke_test_ubuntu / Smoke test (pull_request) check failed ❌ in this PR. However, the same test passes successfully ✅ in my fork (screenshot attached below). Could you please help me investigate this issue?

It would be great if you could:

  1. Restart the failed check to see if it was a transient issue.

  2. Let me know if there are any additional steps I should take to resolve this.

Thank you for your time and assistance!

Снимок экрана 2025-03-03 в 22 44 48
8000

@xiantang
Copy link
Collaborator
xiantang commented Mar 4, 2025

looks pipeline is ok now.

quotedPath := fmt.Sprintf(`"%s"`, path)

if runtime.GOOS == PlatformWindows {
return fmt.Sprintf(`& %s`, quotedPath)
Copy link
Collaborator

Choose a reason for hiding this comment

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

im not using Windows, what does & mean?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Adding & before the path in quotation marks ("path") is necessary for PowerShell or the Windows command prompt to correctly interpret the path with spaces as a command to execute. Without &, a path with spaces can be interpreted as a string, not as a command.
Usage examples:

  1. Running an executable file with spaces in the path:
    If the path to the executable file contains spaces, PowerShell will not be able to execute it without &.
& "C:\Program Files\MyApp\myapp.exe"
  1. Running commands with arguments:
    You can use & to run commands with arguments:
& "C:\Program Files\MyApp\myapp.exe" --arg1 value1

Copy link
Contributor Author
@pkashin pkashin Mar 4, 2025

Choose a reason for hiding this comment

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

Notes:

  1. If the path to an executable file or script is called without &, PowerShell interprets it as a string, not as a command. For example:
"C:\Program Files\MyApp\myapp.exe"

Result:
It just returns the string C:\Program Files\MyApp\myapp.exe , but the command is not executed.

  1. If the path contains spaces and is not enclosed in quotation marks, PowerShell or the command line will not be able to process it correctly. For example:
C:\Program Files\MyApp\myapp.exe

Result:
PowerShell will try to interpret C:\Program As a command, eh Files\MyApp\myapp.exe as an argument, which will lead to an error.

  1. I ran the tests manually locally on Windows, then the coverage reaches 100% for the formatPath() function.

Copy link
Collaborator
@xiantang xiantang left a comment

Choose a reason for hiding this comment

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

LGTM

@xiantang xiantang merged commit a830e5a into air-verse:master Mar 5, 2025
8 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.

air doesn't read the spaces between names of directories
2 participants
0