Skip to content

AffinityHook: quote forwarded arguments by the CommandLineToArgvW rules - #62

Open
jfacemyer wants to merge 1 commit into
noahc3:devfrom
jfacemyer:affinityhook-quote-arguments
Open

jfacemyer wants to merge 1 commit into
noahc3:devfrom
jfacemyer:affinityhook-quote-arguments

Conversation

@jfacemyer

Copy link
Copy Markdown

#45 wraps an argument in quotes when it contains a space. CreateProcess re-parses the string by the CommandLineToArgvW rules, under which that isn't enough:

Argument Today Result
C:\My Folder\ "C:\My Folder\" The trailing backslash escapes the closing quote, and the next argument is swallowed into this one
say "hi" there "say "hi" there" The embedded quotes end the quoting early
(empty) (nothing) The argument disappears
a<TAB>b unquoted Split in two

This quotes per the rules instead: backslashes before a quote or before the closing quote are doubled, embedded quotes are escaped, and an argument is quoted if it's empty or contains whitespace or a quote. net48 has no ProcessStartInfo.ArgumentList, which would otherwise do this.

Checked by round-tripping the generated command lines back through CommandLineToArgvW: plain paths, paths with spaces, several such paths in one line, a trailing backslash, an embedded quote, doubled backslashes, and a mixture all parse back to the original arguments.

noahc3#45 wraps an argument in quotes when it contains a space. CreateProcess
re-parses the Arguments string with the CommandLineToArgvW rules, and
under those rules that is not enough:

  C:\My Folder\    -> "C:\My Folder\"   the trailing backslash escapes
                                         the closing quote and the next
                                         argument is swallowed into it
  say "hi" there   -> the embedded quotes end the quoting early
  (empty)          -> the argument disappears
  tab-separated    -> not quoted at all, split in two

Quote per the rules instead: double the backslashes that precede a quote
or the closing quote, escape embedded quotes, and quote any argument that
is empty or contains whitespace or a quote. net48 has no
ProcessStartInfo.ArgumentList, which would otherwise do this.

Checked by round-tripping generated command lines back through
CommandLineToArgvW: plain paths, paths with spaces, several such paths in
one line, a trailing backslash, an embedded quote, doubled backslashes,
and a mixture all parse back to the original argv.

This branch has not been deployed

No deployments
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.

1 participant