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

Escape quotes in arguments for PowerShell #319

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
}

if (appArguments.length > 0) {
appArguments = appArguments.map(arg => `"\`"${arg}\`""`);
appArguments = appArguments.map(arg => `"\`"${String.prototype.replaceAll.call(arg, '"', '`"')}\`""`);

Check failure on line 205 in index.js

View workflow job for this annotation

GitHub Actions / Node.js 20

Avoid using extended native objects

Check failure on line 205 in index.js

View workflow job for this annotation

GitHub Actions / Node.js 18

Avoid using extended native objects

Check failure on line 205 in index.js

View workflow job for this annotation

GitHub Actions / Node.js 16

Avoid using extended native objects

Check failure on line 205 in index.js

View workflow job for this annotation

GitHub Actions / Node.js 14

Avoid using extended native objects
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
appArguments = appArguments.map(arg => `"\`"${String.prototype.replaceAll.call(arg, '"', '`"')}\`""`);
appArguments = appArguments.map(arg => `"\`"${String(arg).replaceAll('"', '`"')}\`""`);

Copy link
Owner

Choose a reason for hiding this comment

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

This does not handle the case where the quote is already escaped: \"

Copy link
Author

Choose a reason for hiding this comment

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

Sorry for the late response. Could you please elaborate on the \" escaping? I can't find anything on using \ as an escape character in PowerShell.

Alternatively, would it make sense to use single quote strings, as they don't interpret special characters? You can include single quotes in single quote strings by doubling them. This would almost certainly eliminate any edge cases.

encodedArguments.push('-ArgumentList', appArguments.join(','));
}

Expand Down