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

Update quoting for CMD #986

Merged
merged 10 commits into from Jun 24, 2023
Merged

Update quoting for CMD #986

merged 10 commits into from Jun 24, 2023

Conversation

ericcornelissen
Copy link
Owner

@ericcornelissen ericcornelissen commented Jun 21, 2023

Relates to #982

Summary

This addresses incorrect escaping for % when quoting an argument for CMD.

Resources

@ericcornelissen ericcornelissen added the bug Something isn't working label Jun 21, 2023
@github-actions github-actions bot added the test Relates to testing label Jun 21, 2023
This commit is a work in progress...

CMD quoting is weird - It appears to be necessary to preserve whitespace
but you can't disable variable expansion from within quotes (evidenced
by the removal of `_common.cjs` line 68 to 70).

The main progress of this commit is that it fixes the incorrect escaping
of `%` when quoting for CMD. However, it lacks whitespace preservation
which should really be kept - and, to reiterate, whitespace preservation
is impossible without quoting in CMD, as far as I'm aware.
(and correct `getExpectedOutput`  for Unix shells.)
Turns out quoting is necessary in CMD for one important reason: to
prevent argument splitting.

The side affect of quoting whitespace seems to be that, in contrast to
escaping for interpolation, double quotes must be escaped differently.
Hence, this commit also re-introduces the `escapeArgForQuoted` function.
This particular escaping gets a bit confusing when a pre-existing quote
is next to a whitespace character because the inserted quotes from the
actual quoting have an effect on those pre-existing quotes, so they need
to be handled separately.
@ericcornelissen ericcornelissen marked this pull request as ready for review June 22, 2023 21:35
- Include cases where there's multiple for CMD.
- Cover the caret character (`^`) when quoting for Windows.

These cases are based on uncaught mutants.
Per the new quoting strategy for CMD, quoting does not necessarily mean
the resulting string has a quote character at the start and end of the
string. Thus, remove all such checks from the tests.
@ericcornelissen ericcornelissen enabled auto-merge (squash) June 24, 2023 13:38
@ericcornelissen ericcornelissen merged commit 6c9df26 into main Jun 24, 2023
63 of 64 checks passed
@ericcornelissen ericcornelissen deleted the cmd-quoting branch June 24, 2023 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working test Relates to testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant