Skip to content
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

[os2/process]: Don't quote arguments unless needed #4272

Merged
merged 2 commits into from
Oct 4, 2024

Conversation

flysand7
Copy link
Contributor

This PR makes os2.process_start avoid quoting command line arguments, unless they are quoted. The information about which characters need to be quoted is taken from cmd/? help, but also space and a quote is added.

This fixed the behavior of running "cmd.exe" "/c" "<command>", where if /c flag is quoted, the cmd would refuse to understand the location of the command (Don't ask me I have no idea why that's a thing)

C:\Users\flysand7\raven>"cmd" /c "odin test" 
odin is a tool for managing Odin source code.
[...]

C:\Users\flysand7\raven>"cmd" "/c" "odin test" 
'"odin test' is not recognized as an internal or external command,
operable program or batch file.

QUOTED_CHARS :: "()[]{}^=;!'+,`~\" "

@(private)
_char_needs_escape :: proc(ch: u8) -> bool {
Copy link
Sponsor Collaborator

Choose a reason for hiding this comment

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

This function seems unused?

backslashes := 0
for j < len(arg) && arg[j] == '\\' {
backslashes += 1
arg_needs_quoting := false
Copy link
Sponsor Collaborator

Choose a reason for hiding this comment

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

Instead of this boolean and then the if statement to set the boolean and then the if statement with the boolean, why not just if !strings.contains_any(arg, QUOTED_CHARS) {.

@@ -638,6 +638,19 @@ _parse_command_line :: proc(cmd_line_w: [^]u16, allocator: runtime.Allocator) ->
return
}

@(private)
QUOTED_CHARS :: "()[]{}^=;!'+,`~\" "
Copy link
Sponsor Collaborator

Choose a reason for hiding this comment

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

I would personally put this inside the _build_command_line function

@laytan laytan merged commit b5f7332 into odin-lang:master Oct 4, 2024
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.

2 participants